<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class REXML::Element - rexml: Ruby Standard Library Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#class-REXML::Element-label-In+a+Hurry-3F">In a Hurry?</a>
    <li><a href="#class-REXML::Element-label-Name">Name</a>
    <li><a href="#class-REXML::Element-label-Parent">Parent</a>
    <li><a href="#class-REXML::Element-label-Children">Children</a>
    <li><a href="#class-REXML::Element-label-Siblings">Siblings</a>
    <li><a href="#class-REXML::Element-label-Attributes">Attributes</a>
    <li><a href="#class-REXML::Element-label-What-27s+Here">What’s Here</a>
    <li><a href="#class-REXML::Element-label-Methods+for+Creating+an+Element">Methods for Creating an Element</a>
    <li><a href="#class-REXML::Element-label-Methods+for+Attributes">Methods for Attributes</a>
    <li><a href="#class-REXML::Element-label-Methods+for+Children">Methods for Children</a>
    <li><a href="#class-REXML::Element-label-Methods+for+Text+Children">Methods for Text Children</a>
    <li><a href="#class-REXML::Element-label-Methods+for+Other+Children">Methods for Other Children</a>
    <li><a href="#class-REXML::Element-label-Methods+for+Namespaces">Methods for Namespaces</a>
    <li><a href="#class-REXML::Element-label-Methods+for+Querying">Methods for Querying</a>
    <li><a href="#class-REXML::Element-label-One+More+Method">One More Method</a>
    <li><a href="#class-REXML::Element-label-Accessors">Accessors</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Parent
</div>

        
<div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
    <li><a class="include" href="Namespace.html">REXML::Namespace</a>
  </ul>
</div>

        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li class="calls-super" ><a href="#method-c-new">::new</a>
    <li class="calls-super" ><a href="#method-i-5B-5D">#[]</a>
    <li ><a href="#method-i-__to_xpath_helper">#__to_xpath_helper</a>
    <li ><a href="#method-i-add_attribute">#add_attribute</a>
    <li ><a href="#method-i-add_attributes">#add_attributes</a>
    <li ><a href="#method-i-add_element">#add_element</a>
    <li ><a href="#method-i-add_namespace">#add_namespace</a>
    <li ><a href="#method-i-add_text">#add_text</a>
    <li ><a href="#method-i-attribute">#attribute</a>
    <li ><a href="#method-i-cdatas">#cdatas</a>
    <li ><a href="#method-i-clone">#clone</a>
    <li ><a href="#method-i-comments">#comments</a>
    <li ><a href="#method-i-delete_attribute">#delete_attribute</a>
    <li ><a href="#method-i-delete_element">#delete_element</a>
    <li ><a href="#method-i-delete_namespace">#delete_namespace</a>
    <li ><a href="#method-i-document">#document</a>
    <li ><a href="#method-i-each_element">#each_element</a>
    <li ><a href="#method-i-each_element_with_attribute">#each_element_with_attribute</a>
    <li ><a href="#method-i-each_element_with_text">#each_element_with_text</a>
    <li ><a href="#method-i-each_with_something">#each_with_something</a>
    <li ><a href="#method-i-get_elements">#get_elements</a>
    <li ><a href="#method-i-get_text">#get_text</a>
    <li ><a href="#method-i-has_attributes-3F">#has_attributes?</a>
    <li ><a href="#method-i-has_elements-3F">#has_elements?</a>
    <li ><a href="#method-i-has_text-3F">#has_text?</a>
    <li ><a href="#method-i-ignore_whitespace_nodes">#ignore_whitespace_nodes</a>
    <li ><a href="#method-i-inspect">#inspect</a>
    <li ><a href="#method-i-instructions">#instructions</a>
    <li ><a href="#method-i-namespace">#namespace</a>
    <li ><a href="#method-i-namespaces">#namespaces</a>
    <li ><a href="#method-i-next_element">#next_element</a>
    <li ><a href="#method-i-node_type">#node_type</a>
    <li ><a href="#method-i-prefixes">#prefixes</a>
    <li ><a href="#method-i-previous_element">#previous_element</a>
    <li ><a href="#method-i-raw">#raw</a>
    <li ><a href="#method-i-root">#root</a>
    <li ><a href="#method-i-root_node">#root_node</a>
    <li ><a href="#method-i-text">#text</a>
    <li ><a href="#method-i-text-3D">#text=</a>
    <li ><a href="#method-i-texts">#texts</a>
    <li ><a href="#method-i-whitespace">#whitespace</a>
    <li ><a href="#method-i-write">#write</a>
    <li ><a href="#method-i-xpath">#xpath</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-REXML::Element">
    <h1 id="class-REXML::Element" class="class">
      class REXML::Element
    </h1>

    <section class="description">
    
<p>An REXML::Element object represents an XML element.</p>

<p>An element:</p>
<ul><li>
<p>Has a name (string).</p>
</li><li>
<p>May have a parent (another element).</p>
</li><li>
<p>Has zero or more children (other elements, text, CDATA, processing instructions, and comments).</p>
</li><li>
<p>Has zero or more siblings (other elements, text, CDATA, processing instructions, and comments).</p>
</li><li>
<p>Has zero or more named attributes.</p>
</li></ul>

<h2 id="class-REXML::Element-label-In+a+Hurry-3F">In a Hurry?<span><a href="#class-REXML::Element-label-In+a+Hurry-3F">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>If you’re somewhat familiar with XML and have a particular task in mind, you may want to see the <a href="../doc/rexml/tasks/tocs/master_toc_rdoc.html">tasks pages</a>, and in particular, the <a href="../doc/rexml/tasks/tocs/element_toc_rdoc.html">tasks page for elements</a>.</p>

<h3 id="class-REXML::Element-label-Name">Name<span><a href="#class-REXML::Element-label-Name">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>An element has a name, which is initially set when the element is created:</p>

<pre class="ruby"><span class="ruby-identifier">e</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">name</span> <span class="ruby-comment"># =&gt; &quot;foo&quot;</span>
</pre>

<p>The name may be changed:</p>

<pre class="ruby"><span class="ruby-identifier">e</span>.<span class="ruby-identifier">name</span> = <span class="ruby-string">&#39;bar&#39;</span>
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">name</span> <span class="ruby-comment"># =&gt; &quot;bar&quot;</span>
</pre>

<h3 id="class-REXML::Element-label-Parent">Parent<span><a href="#class-REXML::Element-label-Parent">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>An element may have a parent.</p>

<p>Its parent may be assigned explicitly when the element is created:</p>

<pre class="ruby"><span class="ruby-identifier">e0</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">e1</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;bar&#39;</span>, <span class="ruby-identifier">e0</span>)
<span class="ruby-identifier">e1</span>.<span class="ruby-identifier">parent</span> <span class="ruby-comment"># =&gt; &lt;foo&gt; ... &lt;/&gt;</span>
</pre>

<p>Note: the representation of an element always shows the element’s name. If the element has children, the representation indicates that by including an ellipsis (<code>...</code>).</p>

<p>The parent may be assigned explicitly at any time:</p>

<pre class="ruby"><span class="ruby-identifier">e2</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;baz&#39;</span>)
<span class="ruby-identifier">e1</span>.<span class="ruby-identifier">parent</span> = <span class="ruby-identifier">e2</span>
<span class="ruby-identifier">e1</span>.<span class="ruby-identifier">parent</span> <span class="ruby-comment"># =&gt; &lt;baz/&gt;</span>
</pre>

<p>When an element is added as a child, its parent is set automatically:</p>

<pre class="ruby"><span class="ruby-identifier">e1</span>.<span class="ruby-identifier">add_element</span>(<span class="ruby-identifier">e0</span>)
<span class="ruby-identifier">e0</span>.<span class="ruby-identifier">parent</span> <span class="ruby-comment"># =&gt; &lt;bar&gt; ... &lt;/&gt;</span>
</pre>

<p>For an element that has no parent, method <code>parent</code> returns <code>nil</code>.</p>

<h3 id="class-REXML::Element-label-Children">Children<span><a href="#class-REXML::Element-label-Children">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>An element has zero or more children. The children are an ordered collection of all objects whose parent is the element itself.</p>

<p>The children may include any combination of elements, text, comments, processing instructions, and CDATA. (This example keeps things clean by controlling whitespace via a <code>context</code> setting.)</p>

<pre class="ruby"><span class="ruby-identifier">xml_string</span> = <span class="ruby-identifier">&lt;&lt;-EOT</span>
<span class="ruby-value">&lt;root&gt;
  &lt;ele_0/&gt;
  text 0
  &lt;!--comment 0--&gt;
  &lt;?target_0 pi_0?&gt;
  &lt;![CDATA[cdata 0]]&gt;
  &lt;ele_1/&gt;
  text 1
  &lt;!--comment 1--&gt;
  &lt;?target_0 pi_1?&gt;
  &lt;![CDATA[cdata 1]]&gt;
&lt;/root&gt;
</span><span class="ruby-identifier">EOT</span>
<span class="ruby-identifier">context</span> = {<span class="ruby-value">ignore_whitespace_nodes:</span> <span class="ruby-value">:all</span>, <span class="ruby-value">compress_whitespace:</span> <span class="ruby-value">:all</span>}
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">xml_string</span>, <span class="ruby-identifier">context</span>)
<span class="ruby-identifier">root</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>
<span class="ruby-identifier">root</span>.<span class="ruby-identifier">children</span>.<span class="ruby-identifier">size</span> <span class="ruby-comment"># =&gt; 10</span>
<span class="ruby-identifier">root</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">child</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-node">&quot;#{child.class}: #{child}&quot;</span> }
</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-string">&quot;REXML::Element: &lt;ele_0/&gt;&quot;</span>
<span class="ruby-string">&quot;REXML::Text: \n text 0\n &quot;</span>
<span class="ruby-string">&quot;REXML::Comment: comment 0&quot;</span>
<span class="ruby-string">&quot;REXML::Instruction: &lt;?target_0 pi_0?&gt;&quot;</span>
<span class="ruby-string">&quot;REXML::CData: cdata 0&quot;</span>
<span class="ruby-string">&quot;REXML::Element: &lt;ele_1/&gt;&quot;</span>
<span class="ruby-string">&quot;REXML::Text: \n text 1\n &quot;</span>
<span class="ruby-string">&quot;REXML::Comment: comment 1&quot;</span>
<span class="ruby-string">&quot;REXML::Instruction: &lt;?target_0 pi_1?&gt;&quot;</span>
<span class="ruby-string">&quot;REXML::CData: cdata 1&quot;</span>
</pre>

<p>A child may be added using inherited methods <a href="Parent.html#method-i-insert_before"><code>Parent#insert_before</code></a> or <a href="Parent.html#method-i-insert_after"><code>Parent#insert_after</code></a>:</p>

<pre class="ruby"><span class="ruby-identifier">xml_string</span> = <span class="ruby-string">&#39;&lt;root&gt;&lt;a/&gt;&lt;c/&gt;&lt;d/&gt;&lt;/root&gt;&#39;</span>
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">xml_string</span>)
<span class="ruby-identifier">root</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>
<span class="ruby-identifier">c</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>[<span class="ruby-value">1</span>] <span class="ruby-comment"># =&gt; &lt;c/&gt;</span>
<span class="ruby-identifier">root</span>.<span class="ruby-identifier">insert_before</span>(<span class="ruby-identifier">c</span>, <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;b&#39;</span>))
<span class="ruby-identifier">root</span>.<span class="ruby-identifier">to_a</span> <span class="ruby-comment"># =&gt; [&lt;a/&gt;, &lt;b/&gt;, &lt;c/&gt;, &lt;d/&gt;]</span>
</pre>

<p>A child may be replaced using <a href="Parent.html#method-i-replace_child"><code>Parent#replace_child</code></a>:</p>

<pre class="ruby"><span class="ruby-identifier">root</span>.<span class="ruby-identifier">replace_child</span>(<span class="ruby-identifier">c</span>, <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;x&#39;</span>))
<span class="ruby-identifier">root</span>.<span class="ruby-identifier">to_a</span> <span class="ruby-comment"># =&gt; [&lt;a/&gt;, &lt;b/&gt;, &lt;x/&gt;, &lt;d/&gt;]</span>
</pre>

<p>A child may be removed using <a href="Parent.html#method-i-delete"><code>Parent#delete</code></a>:</p>

<pre class="ruby"><span class="ruby-identifier">x</span> = <span class="ruby-identifier">root</span>[<span class="ruby-value">2</span>] <span class="ruby-comment"># =&gt; &lt;x/&gt;</span>
<span class="ruby-identifier">root</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">x</span>)
<span class="ruby-identifier">root</span>.<span class="ruby-identifier">to_a</span> <span class="ruby-comment"># =&gt; [&lt;a/&gt;, &lt;b/&gt;, &lt;d/&gt;]</span>
</pre>

<h3 id="class-REXML::Element-label-Siblings">Siblings<span><a href="#class-REXML::Element-label-Siblings">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>An element has zero or more siblings, which are the other children of the element’s parent.</p>

<p>In the example above, element <code>ele_1</code> is between a CDATA sibling and a text sibling:</p>

<pre class="ruby"><span class="ruby-identifier">ele_1</span> = <span class="ruby-identifier">root</span>[<span class="ruby-value">5</span>]        <span class="ruby-comment"># =&gt; &lt;ele_1/&gt;</span>
<span class="ruby-identifier">ele_1</span>.<span class="ruby-identifier">previous_sibling</span> <span class="ruby-comment"># =&gt; &quot;cdata 0&quot;</span>
<span class="ruby-identifier">ele_1</span>.<span class="ruby-identifier">next_sibling</span>     <span class="ruby-comment"># =&gt; &quot;\n text 1\n &quot;</span>
</pre>

<h3 id="class-REXML::Element-label-Attributes">Attributes<span><a href="#class-REXML::Element-label-Attributes">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>An element has zero or more named attributes.</p>

<p>A new element has no attributes:</p>

<pre class="ruby"><span class="ruby-identifier">e</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">attributes</span>      <span class="ruby-comment"># =&gt; {}</span>
</pre>

<p><a href="Attributes.html"><code>Attributes</code></a> may be added:</p>

<pre class="ruby"><span class="ruby-identifier">e</span>.<span class="ruby-identifier">add_attribute</span>(<span class="ruby-string">&#39;bar&#39;</span>, <span class="ruby-string">&#39;baz&#39;</span>)
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">add_attribute</span>(<span class="ruby-string">&#39;bat&#39;</span>, <span class="ruby-string">&#39;bam&#39;</span>)
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">size</span> <span class="ruby-comment"># =&gt; 2</span>
<span class="ruby-identifier">e</span>[<span class="ruby-string">&#39;bar&#39;</span>]          <span class="ruby-comment"># =&gt; &quot;baz&quot;</span>
<span class="ruby-identifier">e</span>[<span class="ruby-string">&#39;bat&#39;</span>]          <span class="ruby-comment"># =&gt; &quot;bam&quot;</span>
</pre>

<p>An existing attribute may be modified:</p>

<pre class="ruby"><span class="ruby-identifier">e</span>.<span class="ruby-identifier">add_attribute</span>(<span class="ruby-string">&#39;bar&#39;</span>, <span class="ruby-string">&#39;bad&#39;</span>)
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">size</span> <span class="ruby-comment"># =&gt; 2</span>
<span class="ruby-identifier">e</span>[<span class="ruby-string">&#39;bar&#39;</span>]          <span class="ruby-comment"># =&gt; &quot;bad&quot;</span>
</pre>

<p>An existing attribute may be deleted:</p>

<pre class="ruby"><span class="ruby-identifier">e</span>.<span class="ruby-identifier">delete_attribute</span>(<span class="ruby-string">&#39;bar&#39;</span>)
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">size</span> <span class="ruby-comment"># =&gt; 1</span>
<span class="ruby-identifier">e</span>[<span class="ruby-string">&#39;bar&#39;</span>]          <span class="ruby-comment"># =&gt; nil</span>
</pre>

<h2 id="class-REXML::Element-label-What-27s+Here">What’s Here<span><a href="#class-REXML::Element-label-What-27s+Here">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>To begin with, what’s elsewhere?</p>

<p>Class REXML::Element inherits from its ancestor classes:</p>
<ul><li>
<p><a href="Child.html"><code>REXML::Child</code></a></p>
</li><li>
<p><a href="Parent.html"><code>REXML::Parent</code></a></p>
</li></ul>

<p>REXML::Element itself and its ancestors also include modules:</p>
<ul><li>
<p><a href="https://docs.ruby-lang.org/en/master/Enumerable.html">Enumerable</a></p>
</li><li>
<p><a href="Namespace.html"><code>REXML::Namespace</code></a></p>
</li><li>
<p><a href="Node.html"><code>REXML::Node</code></a></p>
</li><li>
<p><a href="XMLTokens.html"><code>REXML::XMLTokens</code></a></p>
</li></ul>

<h3 id="class-REXML::Element-label-Methods+for+Creating+an+Element">Methods for Creating an Element<span><a href="#class-REXML::Element-label-Methods+for+Creating+an+Element">&para;</a> <a href="#top">&uarr;</a></span></h3>
<dl class="rdoc-list note-list"><dt><a href="Element.html#method-c-new"><code>::new</code></a>
<dd>
<p>Returns a new empty element.</p>
</dd><dt><a href="Element.html#method-i-clone"><code>clone</code></a>
<dd>
<p>Returns a clone of another element.</p>
</dd></dl>

<h3 id="class-REXML::Element-label-Methods+for+Attributes">Methods for <a href="Attributes.html"><code>Attributes</code></a><span><a href="#class-REXML::Element-label-Methods+for+Attributes">&para;</a> <a href="#top">&uarr;</a></span></h3>
<dl class="rdoc-list note-list"><dt><a href="#method-i-5B-5D">[attribute_name]</a>
<dd>
<p>Returns an attribute value.</p>
</dd><dt><a href="Element.html#method-i-add_attribute"><code>add_attribute</code></a>
<dd>
<p>Adds a new attribute.</p>
</dd><dt><a href="Element.html#method-i-add_attributes"><code>add_attributes</code></a>
<dd>
<p>Adds multiple new attributes.</p>
</dd><dt><a href="Element.html#method-i-attribute"><code>attribute</code></a>
<dd>
<p>Returns the attribute value for a given name and optional namespace.</p>
</dd><dt><a href="Element.html#method-i-delete_attribute"><code>delete_attribute</code></a>
<dd>
<p>Removes an attribute.</p>
</dd></dl>

<h3 id="class-REXML::Element-label-Methods+for+Children">Methods for Children<span><a href="#class-REXML::Element-label-Methods+for+Children">&para;</a> <a href="#top">&uarr;</a></span></h3>
<dl class="rdoc-list note-list"><dt><a href="#method-i-5B-5D">[index]</a>
<dd>
<p>Returns the child at the given offset.</p>
</dd><dt><a href="Element.html#method-i-add_element"><code>add_element</code></a>
<dd>
<p>Adds an element as the last child.</p>
</dd><dt><a href="Element.html#method-i-delete_element"><code>delete_element</code></a>
<dd>
<p>Deletes a child element.</p>
</dd><dt><a href="Element.html#method-i-each_element"><code>each_element</code></a>
<dd>
<p>Calls the given block with each child element.</p>
</dd><dt><a href="Element.html#method-i-each_element_with_attribute"><code>each_element_with_attribute</code></a>
<dd>
<p>Calls the given block with each child element that meets given criteria, which can include the attribute name.</p>
</dd><dt><a href="Element.html#method-i-each_element_with_text"><code>each_element_with_text</code></a>
<dd>
<p>Calls the given block with each child element that meets given criteria, which can include text.</p>
</dd><dt><a href="Element.html#method-i-get_elements"><code>get_elements</code></a>
<dd>
<p>Returns an array of element children that match a given xpath.</p>
</dd></dl>

<h3 id="class-REXML::Element-label-Methods+for+Text+Children">Methods for Text Children<span><a href="#class-REXML::Element-label-Methods+for+Text+Children">&para;</a> <a href="#top">&uarr;</a></span></h3>
<dl class="rdoc-list note-list"><dt><a href="Element.html#method-i-add_text"><code>add_text</code></a>
<dd>
<p>Adds a text node to the element.</p>
</dd><dt><a href="Element.html#method-i-get_text"><code>get_text</code></a>
<dd>
<p>Returns a text node that meets specified criteria.</p>
</dd><dt><a href="Element.html#method-i-text"><code>text</code></a>
<dd>
<p>Returns the text string from the first node that meets specified criteria.</p>
</dd><dt><a href="Element.html#method-i-texts"><code>texts</code></a>
<dd>
<p>Returns an array of the text children of the element.</p>
</dd><dt><a href="Element.html#method-i-text-3D"><code>text=</code></a>
<dd>
<p>Adds, removes, or replaces the first text child of the element</p>
</dd></dl>

<h3 id="class-REXML::Element-label-Methods+for+Other+Children">Methods for Other Children<span><a href="#class-REXML::Element-label-Methods+for+Other+Children">&para;</a> <a href="#top">&uarr;</a></span></h3>
<dl class="rdoc-list note-list"><dt><a href="Element.html#method-i-cdatas"><code>cdatas</code></a>
<dd>
<p>Returns an array of the cdata children of the element.</p>
</dd><dt><a href="Element.html#method-i-comments"><code>comments</code></a>
<dd>
<p>Returns an array of the comment children of the element.</p>
</dd><dt><a href="Element.html#method-i-instructions"><code>instructions</code></a>
<dd>
<p>Returns an array of the instruction children of the element.</p>
</dd></dl>

<h3 id="class-REXML::Element-label-Methods+for+Namespaces">Methods for Namespaces<span><a href="#class-REXML::Element-label-Methods+for+Namespaces">&para;</a> <a href="#top">&uarr;</a></span></h3>
<dl class="rdoc-list note-list"><dt><a href="Element.html#method-i-add_namespace"><code>add_namespace</code></a>
<dd>
<p>Adds a namespace to the element.</p>
</dd><dt><a href="Element.html#method-i-delete_namespace"><code>delete_namespace</code></a>
<dd>
<p>Removes a namespace from the element.</p>
</dd><dt><a href="Element.html#method-i-namespace"><code>namespace</code></a>
<dd>
<p>Returns the string namespace URI for the element.</p>
</dd><dt><a href="Element.html#method-i-namespaces"><code>namespaces</code></a>
<dd>
<p>Returns a hash of all defined namespaces in the element.</p>
</dd><dt><a href="Element.html#method-i-prefixes"><code>prefixes</code></a>
<dd>
<p>Returns an array of the string prefixes (names) of all defined namespaces in the element</p>
</dd></dl>

<h3 id="class-REXML::Element-label-Methods+for+Querying">Methods for Querying<span><a href="#class-REXML::Element-label-Methods+for+Querying">&para;</a> <a href="#top">&uarr;</a></span></h3>
<dl class="rdoc-list note-list"><dt><a href="Element.html#method-i-document"><code>document</code></a>
<dd>
<p>Returns the document, if any, that the element belongs to.</p>
</dd><dt><a href="Element.html#method-i-root"><code>root</code></a>
<dd>
<p>Returns the most distant element (not document) ancestor of the element.</p>
</dd><dt><a href="Element.html#method-i-root_node"><code>root_node</code></a>
<dd>
<p>Returns the most distant ancestor of the element.</p>
</dd><dt><a href="Element.html#method-i-xpath"><code>xpath</code></a>
<dd>
<p>Returns the string xpath to the element relative to the most distant parent</p>
</dd><dt><a href="Element.html#method-i-has_attributes-3F"><code>has_attributes?</code></a>
<dd>
<p>Returns whether the element has attributes.</p>
</dd><dt><a href="Element.html#method-i-has_elements-3F"><code>has_elements?</code></a>
<dd>
<p>Returns whether the element has elements.</p>
</dd><dt><a href="Element.html#method-i-has_text-3F"><code>has_text?</code></a>
<dd>
<p>Returns whether the element has text.</p>
</dd><dt><a href="Element.html#method-i-next_element"><code>next_element</code></a>
<dd>
<p>Returns the next sibling that is an element.</p>
</dd><dt><a href="Element.html#method-i-previous_element"><code>previous_element</code></a>
<dd>
<p>Returns the previous sibling that is an element.</p>
</dd><dt><a href="Element.html#method-i-raw"><code>raw</code></a>
<dd>
<p>Returns whether raw mode is set for the element.</p>
</dd><dt><a href="Element.html#method-i-whitespace"><code>whitespace</code></a>
<dd>
<p>Returns whether whitespace is respected for the element.</p>
</dd><dt><a href="Element.html#method-i-ignore_whitespace_nodes"><code>ignore_whitespace_nodes</code></a>
<dd>
<p>Returns whether whitespace nodes are to be ignored for the element.</p>
</dd><dt><a href="Element.html#method-i-node_type"><code>node_type</code></a>
<dd>
<p>Returns symbol <code>:element</code>.</p>
</dd></dl>

<h3 id="class-REXML::Element-label-One+More+Method">One More Method<span><a href="#class-REXML::Element-label-One+More+Method">&para;</a> <a href="#top">&uarr;</a></span></h3>
<dl class="rdoc-list note-list"><dt><a href="Element.html#method-i-inspect"><code>inspect</code></a>
<dd>
<p>Returns a string representation of the element.</p>
</dd></dl>

<h3 id="class-REXML::Element-label-Accessors">Accessors<span><a href="#class-REXML::Element-label-Accessors">&para;</a> <a href="#top">&uarr;</a></span></h3>
<dl class="rdoc-list note-list"><dt><a href="Element.html#attribute-i-elements"><code>elements</code></a>
<dd>
<p>Returns the <a href="Elements.html"><code>REXML::Elements</code></a> object for the element.</p>
</dd><dt><a href="Element.html#attribute-i-attributes"><code>attributes</code></a>
<dd>
<p>Returns the <a href="Attributes.html"><code>REXML::Attributes</code></a> object for the element.</p>
</dd><dt><a href="Element.html#attribute-i-context"><code>context</code></a>
<dd>
<p>Returns or sets the context hash for the element.</p>
</dd></dl>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="UNDEFINED">UNDEFINED
          <dd>
        </dl>
        </section>

        <section class="attribute-method-details" class="method-section">
        <header>
        <h3>Attributes</h3>
        </header>

          <div id="attribute-i-attributes" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">attributes</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Mechanisms for accessing attributes and child elements of this element.</p>
              </div>
            </div>
          <div id="attribute-i-context" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">context</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>The context holds information about the processing environment, such as whitespace handling.</p>
              </div>
            </div>
          <div id="attribute-i-elements" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">elements</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              <p>Mechanisms for accessing attributes and child elements of this element.</p>
              </div>
            </div>
            </section>


                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-new" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(name = &#39;UNDEFINED&#39;, parent = nil, context = nil) &rarr; new_element
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(element, parent = nil, context = nil) &rarr; new_element
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns a new REXML::Element object.</p>

<p>When no arguments are given, returns an element with name <code>&#39;UNDEFINED&#39;</code>:</p>

<pre class="ruby"><span class="ruby-identifier">e</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span> <span class="ruby-comment"># =&gt; &lt;UNDEFINED/&gt;</span>
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">class</span>                <span class="ruby-comment"># =&gt; REXML::Element</span>
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">name</span>                 <span class="ruby-comment"># =&gt; &quot;UNDEFINED&quot;</span>
</pre>

<p>When only argument <code>name</code> is given, returns an element of the given name:</p>

<pre class="ruby"><span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foo&#39;</span>) <span class="ruby-comment"># =&gt; &lt;foo/&gt;</span>
</pre>

<p>When only argument <code>element</code> is given, it must be an REXML::Element object; returns a shallow copy of the given element:</p>

<pre class="ruby"><span class="ruby-identifier">e0</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">e1</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">e0</span>) <span class="ruby-comment"># =&gt; &lt;foo/&gt;</span>
</pre>

<p>When argument <code>parent</code> is also given, it must be an <a href="Parent.html"><code>REXML::Parent</code></a> object:</p>

<pre class="ruby"><span class="ruby-identifier">e</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foo&#39;</span>, <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Parent</span>.<span class="ruby-identifier">new</span>)
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">parent</span> <span class="ruby-comment"># =&gt; #&lt;REXML::Parent @parent=nil, @children=[&lt;foo/&gt;]&gt;</span>
</pre>

<p>When argument <code>context</code> is also given, it must be a hash representing the context for the element; see <a href="../doc/rexml/context_rdoc.html">Element Context</a>:</p>

<pre class="ruby"><span class="ruby-identifier">e</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foo&#39;</span>, <span class="ruby-keyword">nil</span>, {<span class="ruby-value">raw:</span> <span class="ruby-value">:all</span>})
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">context</span> <span class="ruby-comment"># =&gt; {:raw=&gt;:all}</span>
</pre>
                                <div class="method-calls-super">
                                  Calls superclass method
                                  
                              </div>

                              <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 327</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>( <span class="ruby-identifier">arg</span> = <span class="ruby-constant">UNDEFINED</span>, <span class="ruby-identifier">parent</span>=<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">context</span>=<span class="ruby-keyword">nil</span> )
  <span class="ruby-keyword">super</span>(<span class="ruby-identifier">parent</span>)

  <span class="ruby-ivar">@elements</span> = <span class="ruby-constant">Elements</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword">self</span>)
  <span class="ruby-ivar">@attributes</span> = <span class="ruby-constant">Attributes</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword">self</span>)
  <span class="ruby-ivar">@context</span> = <span class="ruby-identifier">context</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">arg</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">String</span>
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">name</span> = <span class="ruby-identifier">arg</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">arg</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Element</span>
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">name</span> = <span class="ruby-identifier">arg</span>.<span class="ruby-identifier">expanded_name</span>
    <span class="ruby-identifier">arg</span>.<span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">each_attribute</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">attribute</span><span class="ruby-operator">|</span>
      <span class="ruby-ivar">@attributes</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">Attribute</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">attribute</span> )
    }
    <span class="ruby-ivar">@context</span> = <span class="ruby-identifier">arg</span>.<span class="ruby-identifier">context</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-5B-5D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          [index] &rarr; object
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          [attr_name] &rarr; attr_value
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          [attr_sym] &rarr; attr_value
                              </span>
                            </div>

                            <div class="method-description">
                              <p>With integer argument <code>index</code> given, returns the child at offset <code>index</code>, or <code>nil</code> if none:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&#39;&gt;&lt;root&gt;&lt;a/&gt;text&lt;b/&gt;more&lt;c/&gt;&lt;/root&gt;&#39;</span>
<span class="ruby-identifier">root</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>
(<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-identifier">root</span>.<span class="ruby-identifier">size</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">node</span> = <span class="ruby-identifier">root</span>[<span class="ruby-identifier">index</span>]
  <span class="ruby-identifier">p</span> <span class="ruby-node">&quot;#{index}: #{node} (#{node.class})&quot;</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Output:</p>

<pre class="ruby"><span class="ruby-string">&quot;0: &lt;a/&gt; (REXML::Element)&quot;</span>
<span class="ruby-string">&quot;1: text (REXML::Text)&quot;</span>
<span class="ruby-string">&quot;2: &lt;b/&gt; (REXML::Element)&quot;</span>
<span class="ruby-string">&quot;3: more (REXML::Text)&quot;</span>
<span class="ruby-string">&quot;4: &lt;c/&gt; (REXML::Element)&quot;</span>
<span class="ruby-string">&quot;5:  (NilClass)&quot;</span>
</pre>

<p>With string argument <code>attr_name</code> given, returns the string value for the given attribute name if it exists, otherwise <code>nil</code>:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&lt;root attr=&quot;value&quot;&gt;&lt;/root&gt;&#39;</span>)
<span class="ruby-identifier">root</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>
<span class="ruby-identifier">root</span>[<span class="ruby-string">&#39;attr&#39;</span>]   <span class="ruby-comment"># =&gt; &quot;value&quot;</span>
<span class="ruby-identifier">root</span>[<span class="ruby-string">&#39;nosuch&#39;</span>] <span class="ruby-comment"># =&gt; nil</span>
</pre>

<p>With symbol argument <code>attr_sym</code> given, returns <code>[attr_sym.to_s]</code>:</p>

<pre class="ruby"><span class="ruby-identifier">root</span>[<span class="ruby-value">:attr</span>]   <span class="ruby-comment"># =&gt; &quot;value&quot;</span>
<span class="ruby-identifier">root</span>[<span class="ruby-value">:nosuch</span>] <span class="ruby-comment"># =&gt; nil</span>
</pre>
                                <div class="method-calls-super">
                                  Calls superclass method
                                  
                              </div>

                              <div class="method-source-code" id="5B-5D-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1245</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">[]</span>(<span class="ruby-identifier">name_or_index</span>)
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">name_or_index</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">String</span>
    <span class="ruby-identifier">attributes</span>[<span class="ruby-identifier">name_or_index</span>]
  <span class="ruby-keyword">when</span> <span class="ruby-constant">Symbol</span>
    <span class="ruby-identifier">attributes</span>[<span class="ruby-identifier">name_or_index</span>.<span class="ruby-identifier">to_s</span>]
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">super</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-add_attribute" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          add_attribute(name, value) &rarr; value
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          add_attribute(attribute) &rarr; attribute
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Adds an attribute to this element, overwriting any existing attribute by the same name.</p>

<p>With string argument <code>name</code> and object <code>value</code> are given, adds the attribute created with that name and value:</p>

<pre class="ruby"><span class="ruby-identifier">e</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">add_attribute</span>(<span class="ruby-string">&#39;attr&#39;</span>, <span class="ruby-string">&#39;value&#39;</span>) <span class="ruby-comment"># =&gt; &quot;value&quot;</span>
<span class="ruby-identifier">e</span>[<span class="ruby-string">&#39;attr&#39;</span>] <span class="ruby-comment"># =&gt; &quot;value&quot;</span>
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">add_attribute</span>(<span class="ruby-string">&#39;attr&#39;</span>, <span class="ruby-string">&#39;VALUE&#39;</span>) <span class="ruby-comment"># =&gt; &quot;VALUE&quot;</span>
<span class="ruby-identifier">e</span>[<span class="ruby-string">&#39;attr&#39;</span>] <span class="ruby-comment"># =&gt; &quot;VALUE&quot;</span>
</pre>

<p>With only attribute object <code>attribute</code> given, adds the given attribute:</p>

<pre class="ruby"><span class="ruby-identifier">a</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Attribute</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;attr&#39;</span>, <span class="ruby-string">&#39;value&#39;</span>)
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">add_attribute</span>(<span class="ruby-identifier">a</span>) <span class="ruby-comment"># =&gt; attr=&#39;value&#39;</span>
<span class="ruby-identifier">e</span>[<span class="ruby-string">&#39;attr&#39;</span>] <span class="ruby-comment"># =&gt; &quot;value&quot;</span>
<span class="ruby-identifier">a</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Attribute</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;attr&#39;</span>, <span class="ruby-string">&#39;VALUE&#39;</span>)
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">add_attribute</span>(<span class="ruby-identifier">a</span>) <span class="ruby-comment"># =&gt; attr=&#39;VALUE&#39;</span>
<span class="ruby-identifier">e</span>[<span class="ruby-string">&#39;attr&#39;</span>] <span class="ruby-comment"># =&gt; &quot;VALUE&quot;</span>
</pre>

                              <div class="method-source-code" id="add_attribute-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1349</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">add_attribute</span>( <span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>=<span class="ruby-keyword">nil</span> )
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Attribute</span>
    <span class="ruby-ivar">@attributes</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">key</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-ivar">@attributes</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-add_attributes" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          add_attributes(hash) &rarr; hash
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          add_attributes(array)
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Adds zero or more attributes to the element; returns the argument.</p>

<p>If hash argument <code>hash</code> is given, each key must be a string; adds each attribute created with the key/value pair:</p>

<pre class="ruby"><span class="ruby-identifier">e</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">h</span> = {<span class="ruby-string">&#39;foo&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;bar&#39;</span>, <span class="ruby-string">&#39;baz&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;bat&#39;</span>}
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">add_attributes</span>(<span class="ruby-identifier">h</span>)
</pre>

<p>If argument <code>array</code> is given, each array member must be a 2-element array &lt;tt&gt;[name, value]; each name must be a string:</p>

<pre class="ruby"><span class="ruby-identifier">e</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">a</span> = [[<span class="ruby-string">&#39;foo&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;bar&#39;</span>], [<span class="ruby-string">&#39;baz&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;bat&#39;</span>]]
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">add_attributes</span>(<span class="ruby-identifier">a</span>)
</pre>

                              <div class="method-source-code" id="add_attributes-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1380</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">add_attributes</span> <span class="ruby-identifier">hash</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">hash</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Hash</span>
    <span class="ruby-identifier">hash</span>.<span class="ruby-identifier">each_pair</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@attributes</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span> }
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">hash</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Array</span>
    <span class="ruby-identifier">hash</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@attributes</span>[ <span class="ruby-identifier">value</span>[<span class="ruby-value">0</span>] ] = <span class="ruby-identifier">value</span>[<span class="ruby-value">1</span>] }
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-add_element" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          add_element(name, attributes = nil) &rarr; new_element
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          add_element(element, attributes = nil) &rarr; element
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Adds a child element, optionally setting attributes on the added element; returns the added element.</p>

<p>With string argument <code>name</code>, creates a new element with that name and adds the new element as a child:</p>

<pre class="ruby"><span class="ruby-identifier">e0</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">e0</span>.<span class="ruby-identifier">add_element</span>(<span class="ruby-string">&#39;bar&#39;</span>)
<span class="ruby-identifier">e0</span>[<span class="ruby-value">0</span>] <span class="ruby-comment"># =&gt; &lt;bar/&gt;</span>
</pre>

<p>With argument <code>name</code> and hash argument <code>attributes</code>, sets attributes on the new element:</p>

<pre class="ruby"><span class="ruby-identifier">e0</span>.<span class="ruby-identifier">add_element</span>(<span class="ruby-string">&#39;baz&#39;</span>, {<span class="ruby-string">&#39;bat&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;0&#39;</span>, <span class="ruby-string">&#39;bam&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;1&#39;</span>})
<span class="ruby-identifier">e0</span>[<span class="ruby-value">1</span>] <span class="ruby-comment"># =&gt; &lt;baz bat=&#39;0&#39; bam=&#39;1&#39;/&gt;</span>
</pre>

<p>With element argument <code>element</code>, adds that element as a child:</p>

<pre class="ruby"><span class="ruby-identifier">e0</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">e1</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;bar&#39;</span>)
<span class="ruby-identifier">e0</span>.<span class="ruby-identifier">add_element</span>(<span class="ruby-identifier">e1</span>)
<span class="ruby-identifier">e0</span>[<span class="ruby-value">0</span>] <span class="ruby-comment"># =&gt; &lt;bar/&gt;</span>
</pre>

<p>With argument <code>element</code> and hash argument <code>attributes</code>, sets attributes on the added element:</p>

<pre class="ruby"><span class="ruby-identifier">e0</span>.<span class="ruby-identifier">add_element</span>(<span class="ruby-identifier">e1</span>, {<span class="ruby-string">&#39;bat&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;0&#39;</span>, <span class="ruby-string">&#39;bam&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;1&#39;</span>})
<span class="ruby-identifier">e0</span>[<span class="ruby-value">1</span>] <span class="ruby-comment"># =&gt; &lt;bar bat=&#39;0&#39; bam=&#39;1&#39;/&gt;</span>
</pre>

                              <div class="method-source-code" id="add_element-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 731</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">add_element</span> <span class="ruby-identifier">element</span>, <span class="ruby-identifier">attrs</span>=<span class="ruby-keyword">nil</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-string">&quot;First argument must be either an element name, or an Element object&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">nil?</span>
  <span class="ruby-identifier">el</span> = <span class="ruby-ivar">@elements</span>.<span class="ruby-identifier">add</span>(<span class="ruby-identifier">element</span>)
  <span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">el</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-identifier">key</span>]=<span class="ruby-identifier">value</span>
  <span class="ruby-keyword">end</span>       <span class="ruby-keyword">if</span> <span class="ruby-identifier">attrs</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Hash</span>
  <span class="ruby-identifier">el</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-add_namespace" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          add_namespace(prefix, uri = nil) &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Adds a namespace to the element; returns <code>self</code>.</p>

<p>With the single argument <code>prefix</code>, adds a namespace using the given <code>prefix</code> and the namespace URI:</p>

<pre class="ruby"><span class="ruby-identifier">e</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">add_namespace</span>(<span class="ruby-string">&#39;bar&#39;</span>)
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">namespaces</span> <span class="ruby-comment"># =&gt; {&quot;xmlns&quot;=&gt;&quot;bar&quot;}</span>
</pre>

<p>With both arguments <code>prefix</code> and <code>uri</code> given, adds a namespace using both arguments:</p>

<pre class="ruby"><span class="ruby-identifier">e</span>.<span class="ruby-identifier">add_namespace</span>(<span class="ruby-string">&#39;baz&#39;</span>, <span class="ruby-string">&#39;bat&#39;</span>)
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">namespaces</span> <span class="ruby-comment"># =&gt; {&quot;xmlns&quot;=&gt;&quot;bar&quot;, &quot;baz&quot;=&gt;&quot;bat&quot;}</span>
</pre>

                              <div class="method-source-code" id="add_namespace-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 654</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">add_namespace</span>( <span class="ruby-identifier">prefix</span>, <span class="ruby-identifier">uri</span>=<span class="ruby-keyword">nil</span> )
  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">uri</span>
    <span class="ruby-ivar">@attributes</span>[<span class="ruby-string">&quot;xmlns&quot;</span>] = <span class="ruby-identifier">prefix</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">prefix</span> = <span class="ruby-node">&quot;xmlns:#{prefix}&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">prefix</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/^xmlns:/</span>
    <span class="ruby-ivar">@attributes</span>[ <span class="ruby-identifier">prefix</span> ] = <span class="ruby-identifier">uri</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-add_text" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          add_text(string) &rarr; nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          add_text(text_node) &rarr; self
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Adds text to the element.</p>

<p>When string argument <code>string</code> is given, returns <code>nil</code>.</p>

<p>If the element has no child text node, creates a REXML::Text object using the string, honoring the current settings for whitespace and raw, then adds that node to the element:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&lt;a&gt;&lt;b/&gt;&lt;/a&gt;&#39;</span>)
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">add_text</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">to_a</span> <span class="ruby-comment"># =&gt; [&lt;b/&gt;, &quot;foo&quot;]</span>
</pre>

<p>If the element has child text nodes, appends the string to the <em>last</em> text node:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&lt;a&gt;foo&lt;b/&gt;bar&lt;/a&gt;&#39;</span>)
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">add_text</span>(<span class="ruby-string">&#39;baz&#39;</span>)
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">to_a</span> <span class="ruby-comment"># =&gt; [&quot;foo&quot;, &lt;b/&gt;, &quot;barbaz&quot;]</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">add_text</span>(<span class="ruby-string">&#39;baz&#39;</span>)
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">to_a</span> <span class="ruby-comment"># =&gt; [&quot;foo&quot;, &lt;b/&gt;, &quot;barbazbaz&quot;]</span>
</pre>

<p>When text node argument <code>text_node</code> is given, appends the node as the last text node in the element; returns <code>self</code>:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&lt;a&gt;foo&lt;b/&gt;bar&lt;/a&gt;&#39;</span>)
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">add_text</span>(<span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Text</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;baz&#39;</span>))
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">to_a</span> <span class="ruby-comment"># =&gt; [&quot;foo&quot;, &lt;b/&gt;, &quot;bar&quot;, &quot;baz&quot;]</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">add_text</span>(<span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Text</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;baz&#39;</span>))
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">to_a</span> <span class="ruby-comment"># =&gt; [&quot;foo&quot;, &lt;b/&gt;, &quot;bar&quot;, &quot;baz&quot;, &quot;baz&quot;]</span>
</pre>

                              <div class="method-source-code" id="add_text-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1146</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">add_text</span>( <span class="ruby-identifier">text</span> )
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">text</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">String</span>
    <span class="ruby-keyword">if</span> <span class="ruby-ivar">@children</span>[<span class="ruby-value">-1</span>].<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Text</span>
      <span class="ruby-ivar">@children</span>[<span class="ruby-value">-1</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">text</span>
      <span class="ruby-keyword">return</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">text</span> = <span class="ruby-constant">Text</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">text</span>, <span class="ruby-identifier">whitespace</span>(), <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">raw</span>() )
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">self</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">text</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">text</span>.<span class="ruby-identifier">nil?</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-attribute" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          attribute(name, namespace = nil)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the string value for the given attribute name.</p>

<p>With only argument <code>name</code> given, returns the value of the named attribute if it exists, otherwise <code>nil</code>:</p>

<pre class="ruby"><span class="ruby-identifier">xml_string</span> = <span class="ruby-identifier">&lt;&lt;-EOT</span>
<span class="ruby-value">  &lt;root xmlns=&quot;ns0&quot;&gt;
    &lt;a xmlns=&quot;ns1&quot; attr=&quot;value&quot;&gt;&lt;/a&gt;
    &lt;b xmlns=&quot;ns2&quot; attr=&quot;value&quot;&gt;&lt;/b&gt;
    &lt;c attr=&quot;value&quot;/&gt;
 &lt;/root&gt;
</span><span class="ruby-identifier">EOT</span>
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">xml_string</span>)
<span class="ruby-identifier">root</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">root</span>[<span class="ruby-value">1</span>] <span class="ruby-comment"># =&gt; &lt;a xmlns=&#39;ns1&#39; attr=&#39;value&#39;/&gt;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">attribute</span>(<span class="ruby-string">&#39;attr&#39;</span>) <span class="ruby-comment"># =&gt; attr=&#39;value&#39;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">attribute</span>(<span class="ruby-string">&#39;nope&#39;</span>) <span class="ruby-comment"># =&gt; nil</span>
</pre>

<p>With arguments <code>name</code> and <code>namespace</code> given, returns the value of the named attribute if it exists, otherwise <code>nil</code>:</p>

<pre class="ruby"><span class="ruby-identifier">xml_string</span> = <span class="ruby-string">&quot;&lt;root xmlns:a=&#39;a&#39; a:x=&#39;a:x&#39; x=&#39;x&#39;/&gt;&quot;</span>
<span class="ruby-identifier">document</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">xml_string</span>)
<span class="ruby-identifier">document</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">attribute</span>(<span class="ruby-string">&quot;x&quot;</span>)      <span class="ruby-comment"># =&gt; x=&#39;x&#39;</span>
<span class="ruby-identifier">document</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">attribute</span>(<span class="ruby-string">&quot;x&quot;</span>, <span class="ruby-string">&quot;a&quot;</span>) <span class="ruby-comment"># =&gt; a:x=&#39;a:x&#39;</span>
</pre>

                              <div class="method-source-code" id="attribute-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1286</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">attribute</span>( <span class="ruby-identifier">name</span>, <span class="ruby-identifier">namespace</span>=<span class="ruby-keyword">nil</span> )
  <span class="ruby-identifier">prefix</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">namespaces</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-value">:key</span>
    <span class="ruby-identifier">prefix</span> = <span class="ruby-identifier">namespaces</span>.<span class="ruby-identifier">key</span>(<span class="ruby-identifier">namespace</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">namespace</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">prefix</span> = <span class="ruby-identifier">namespaces</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">namespace</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">namespace</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">prefix</span> = <span class="ruby-keyword">nil</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">prefix</span> <span class="ruby-operator">==</span> <span class="ruby-string">&#39;xmlns&#39;</span>

  <span class="ruby-identifier">ret_val</span> =
    <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">get_attribute</span>( <span class="ruby-node">&quot;#{prefix ? prefix + &#39;:&#39; : &#39;&#39;}#{name}&quot;</span> )

  <span class="ruby-keyword">return</span> <span class="ruby-identifier">ret_val</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">ret_val</span>.<span class="ruby-identifier">nil?</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">prefix</span>.<span class="ruby-identifier">nil?</span>

  <span class="ruby-comment"># now check that prefix&#39;es namespace is not the same as the</span>
  <span class="ruby-comment"># default namespace</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">nil</span> <span class="ruby-keyword">unless</span> ( <span class="ruby-identifier">namespaces</span>[ <span class="ruby-identifier">prefix</span> ] <span class="ruby-operator">==</span> <span class="ruby-identifier">namespaces</span>[ <span class="ruby-string">&#39;xmlns&#39;</span> ] )

  <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">get_attribute</span>( <span class="ruby-identifier">name</span> )

<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-cdatas" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          cdatas &rarr; array_of_cdata_children
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a frozen array of the <a href="CData.html"><code>REXML::CData</code></a> children of the element:</p>

<pre class="ruby"><span class="ruby-identifier">xml_string</span> = <span class="ruby-identifier">&lt;&lt;-EOT</span>
<span class="ruby-value">  &lt;root&gt;
    &lt;![CDATA[foo]]&gt;
    &lt;![CDATA[bar]]&gt;
  &lt;/root&gt;
</span><span class="ruby-identifier">EOT</span>
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">xml_string</span>)
<span class="ruby-identifier">cds</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">cdatas</span>      <span class="ruby-comment"># =&gt; [&quot;foo&quot;, &quot;bar&quot;]</span>
<span class="ruby-identifier">cds</span>.<span class="ruby-identifier">frozen?</span>              <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">cds</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">cd</span><span class="ruby-operator">|</span> <span class="ruby-identifier">cd</span>.<span class="ruby-identifier">class</span> } <span class="ruby-comment"># =&gt; [REXML::CData, REXML::CData]</span>
</pre>

                              <div class="method-source-code" id="cdatas-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1424</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">cdatas</span>
  <span class="ruby-identifier">find_all</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">child</span><span class="ruby-operator">|</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">CData</span> }.<span class="ruby-identifier">freeze</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-clone" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          clone &rarr; new_element
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a shallow copy of the element, containing the name and attributes, but not the parent or children:</p>

<pre class="ruby"><span class="ruby-identifier">e</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">add_attributes</span>({<span class="ruby-string">&#39;bar&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">0</span>, <span class="ruby-string">&#39;baz&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">1</span>})
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">clone</span> <span class="ruby-comment"># =&gt; &lt;foo bar=&#39;0&#39; baz=&#39;1&#39;/&gt;</span>
</pre>

                              <div class="method-source-code" id="clone-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 391</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">clone</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-comments" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          comments &rarr; array_of_comment_children
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a frozen array of the <a href="Comment.html"><code>REXML::Comment</code></a> children of the element:</p>

<pre class="ruby"><span class="ruby-identifier">xml_string</span> = <span class="ruby-identifier">&lt;&lt;-EOT</span>
<span class="ruby-value">  &lt;root&gt;
    &lt;!--foo--&gt;
    &lt;!--bar--&gt;
  &lt;/root&gt;
</span><span class="ruby-identifier">EOT</span>
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">xml_string</span>)
<span class="ruby-identifier">cs</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">comments</span>
<span class="ruby-identifier">cs</span>.<span class="ruby-identifier">frozen?</span>            <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">cs</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">class</span> } <span class="ruby-comment"># =&gt; [REXML::Comment, REXML::Comment]</span>
<span class="ruby-identifier">cs</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">to_s</span> }  <span class="ruby-comment"># =&gt; [&quot;foo&quot;, &quot;bar&quot;]</span>
</pre>

                              <div class="method-source-code" id="comments-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1445</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">comments</span>
  <span class="ruby-identifier">find_all</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">child</span><span class="ruby-operator">|</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Comment</span> }.<span class="ruby-identifier">freeze</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-delete_attribute" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          delete_attribute(name) &rarr; removed_attribute or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Removes a named attribute if it exists; returns the removed attribute if found, otherwise <code>nil</code>:</p>

<pre class="ruby"><span class="ruby-identifier">e</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">add_attribute</span>(<span class="ruby-string">&#39;bar&#39;</span>, <span class="ruby-string">&#39;baz&#39;</span>)
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">delete_attribute</span>(<span class="ruby-string">&#39;bar&#39;</span>) <span class="ruby-comment"># =&gt; &lt;bar/&gt;</span>
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">delete_attribute</span>(<span class="ruby-string">&#39;bar&#39;</span>) <span class="ruby-comment"># =&gt; nil</span>
</pre>

                              <div class="method-source-code" id="delete_attribute-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1399</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">delete_attribute</span>(<span class="ruby-identifier">key</span>)
  <span class="ruby-identifier">attr</span> = <span class="ruby-ivar">@attributes</span>.<span class="ruby-identifier">get_attribute</span>(<span class="ruby-identifier">key</span>)
  <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">remove</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">nil?</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-delete_element" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          delete_element(index) &rarr; removed_element or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          delete_element(element) &rarr; removed_element or nil
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          delete_element(xpath) &rarr; removed_element or nil
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Deletes a child element.</p>

<p>When 1-based integer argument <code>index</code> is given, removes and returns the child element at that offset if it exists; indexing does not include text nodes; returns <code>nil</code> if the element does not exist:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&#39;&lt;a&gt;&lt;b/&gt;text&lt;c/&gt;&lt;/a&gt;&#39;</span>
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>          <span class="ruby-comment"># =&gt; &lt;a&gt; ... &lt;/&gt;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">delete_element</span>(<span class="ruby-value">1</span>) <span class="ruby-comment"># =&gt; &lt;b/&gt;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">delete_element</span>(<span class="ruby-value">1</span>) <span class="ruby-comment"># =&gt; &lt;c/&gt;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">delete_element</span>(<span class="ruby-value">1</span>) <span class="ruby-comment"># =&gt; nil</span>
</pre>

<p>When element argument <code>element</code> is given, removes and returns that child element if it exists, otherwise returns <code>nil</code>:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&#39;&lt;a&gt;&lt;b/&gt;text&lt;c/&gt;&lt;/a&gt;&#39;</span>
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>          <span class="ruby-comment"># =&gt; &lt;a&gt; ... &lt;/&gt;</span>
<span class="ruby-identifier">c</span> = <span class="ruby-identifier">a</span>[<span class="ruby-value">2</span>]            <span class="ruby-comment"># =&gt; &lt;c/&gt;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">delete_element</span>(<span class="ruby-identifier">c</span>) <span class="ruby-comment"># =&gt; &lt;c/&gt;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">delete_element</span>(<span class="ruby-identifier">c</span>) <span class="ruby-comment"># =&gt; nil</span>
</pre>

<p>When xpath argument <code>xpath</code> is given, removes and returns the element at xpath if it exists, otherwise returns <code>nil</code>:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&#39;&lt;a&gt;&lt;b/&gt;text&lt;c/&gt;&lt;/a&gt;&#39;</span>
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>              <span class="ruby-comment"># =&gt; &lt;a&gt; ... &lt;/&gt;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">delete_element</span>(<span class="ruby-string">&#39;//c&#39;</span>) <span class="ruby-comment"># =&gt; &lt;c/&gt;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">delete_element</span>(<span class="ruby-string">&#39;//c&#39;</span>) <span class="ruby-comment"># =&gt; nil</span>
</pre>

                              <div class="method-source-code" id="delete_element-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 777</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">delete_element</span> <span class="ruby-identifier">element</span>
  <span class="ruby-ivar">@elements</span>.<span class="ruby-identifier">delete</span> <span class="ruby-identifier">element</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-delete_namespace" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          delete_namespace(namespace = &#39;xmlns&#39;) &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Removes a namespace from the element.</p>

<p>With no argument, removes the default namespace:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&quot;&lt;a xmlns:foo=&#39;bar&#39; xmlns=&#39;twiddle&#39;/&gt;&quot;</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-comment"># =&gt; &quot;&lt;a xmlns:foo=&#39;bar&#39; xmlns=&#39;twiddle&#39;/&gt;&quot;</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">delete_namespace</span> <span class="ruby-comment"># =&gt; &lt;a xmlns:foo=&#39;bar&#39;/&gt;</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-comment"># =&gt; &quot;&lt;a xmlns:foo=&#39;bar&#39;/&gt;&quot;</span>
</pre>

<p>With argument <code>namespace</code>, removes the specified namespace:</p>

<pre class="ruby"><span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">delete_namespace</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-comment"># =&gt; &quot;&lt;a/&gt;&quot;</span>
</pre>

<p>Does nothing if no such namespace is found:</p>

<pre class="ruby"><span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">delete_namespace</span>(<span class="ruby-string">&#39;nosuch&#39;</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-comment"># =&gt; &quot;&lt;a/&gt;&quot;</span>
</pre>

                              <div class="method-source-code" id="delete_namespace-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 686</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">delete_namespace</span> <span class="ruby-identifier">namespace</span>=<span class="ruby-string">&quot;xmlns&quot;</span>
  <span class="ruby-identifier">namespace</span> = <span class="ruby-node">&quot;xmlns:#{namespace}&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">namespace</span> <span class="ruby-operator">==</span> <span class="ruby-string">&#39;xmlns&#39;</span>
  <span class="ruby-identifier">attribute</span> = <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">get_attribute</span>(<span class="ruby-identifier">namespace</span>)
  <span class="ruby-identifier">attribute</span>.<span class="ruby-identifier">remove</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">attribute</span>.<span class="ruby-identifier">nil?</span>
  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-document" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          document &rarr; document or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>If the element is part of a document, returns that document:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&lt;a&gt;&lt;b&gt;&lt;c/&gt;&lt;/b&gt;&lt;/a&gt;&#39;</span>)
<span class="ruby-identifier">top_element</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">first</span>
<span class="ruby-identifier">child</span> = <span class="ruby-identifier">top_element</span>.<span class="ruby-identifier">first</span>
<span class="ruby-identifier">top_element</span>.<span class="ruby-identifier">document</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">d</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">child</span>.<span class="ruby-identifier">document</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">d</span>       <span class="ruby-comment"># =&gt; true</span>
</pre>

<p>If the element is not part of a document, returns <code>nil</code>:</p>

<pre class="ruby"><span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">document</span> <span class="ruby-comment"># =&gt; nil</span>
</pre>

<p>For a document, returns <code>self</code>:</p>

<pre class="ruby"><span class="ruby-identifier">d</span>.<span class="ruby-identifier">document</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">d</span>           <span class="ruby-comment"># =&gt; true</span>
</pre>

<p>Related: <a href="Element.html#method-i-root"><code>root</code></a>, <a href="Element.html#method-i-root_node"><code>root_node</code></a>.</p>

                              <div class="method-source-code" id="document-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 478</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">document</span>
  <span class="ruby-identifier">rt</span> = <span class="ruby-identifier">root</span>
  <span class="ruby-identifier">rt</span>.<span class="ruby-identifier">parent</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">rt</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each_element" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          each_element {|e| ... }
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Calls the given block with each child element:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&#39;&lt;a&gt;&lt;b&gt;b&lt;/b&gt;&lt;c&gt;b&lt;/c&gt;&lt;d&gt;d&lt;/d&gt;&lt;e/&gt;&lt;/a&gt;&#39;</span>
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">each_element</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">e</span> }
</pre>

<p>Output:</p>

<pre>&lt;b&gt; ... &lt;/&gt;
&lt;c&gt; ... &lt;/&gt;
&lt;d&gt; ... &lt;/&gt;
&lt;e/&gt;</pre>

                              <div class="method-source-code" id="each_element-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 929</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">each_element</span>( <span class="ruby-identifier">xpath</span>=<span class="ruby-keyword">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span> ) <span class="ruby-comment"># :yields: Element</span>
  <span class="ruby-ivar">@elements</span>.<span class="ruby-identifier">each</span>( <span class="ruby-identifier">xpath</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span> )
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each_element_with_attribute" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          each_element_with_attribute(attr_name, value = nil, max = 0, xpath = nil) {|e| ... }
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Calls the given block with each child element that meets given criteria.</p>

<p>When only string argument <code>attr_name</code> is given, calls the block with each child element that has that attribute:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&#39;&lt;a&gt;&lt;b id=&quot;1&quot;/&gt;&lt;c id=&quot;2&quot;/&gt;&lt;d id=&quot;1&quot;/&gt;&lt;e/&gt;&lt;/a&gt;&#39;</span>
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">each_element_with_attribute</span>(<span class="ruby-string">&#39;id&#39;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">e</span> }
</pre>

<p>Output:</p>

<pre>&lt;b id=&#39;1&#39;/&gt;
&lt;c id=&#39;2&#39;/&gt;
&lt;d id=&#39;1&#39;/&gt;</pre>

<p>With argument <code>attr_name</code> and string argument <code>value</code> given, calls the block with each child element that has that attribute with that value:</p>

<pre class="ruby"><span class="ruby-identifier">a</span>.<span class="ruby-identifier">each_element_with_attribute</span>(<span class="ruby-string">&#39;id&#39;</span>, <span class="ruby-string">&#39;1&#39;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">e</span> }
</pre>

<p>Output:</p>

<pre>&lt;b id=&#39;1&#39;/&gt;
&lt;d id=&#39;1&#39;/&gt;</pre>

<p>With arguments <code>attr_name</code>, <code>value</code>, and integer argument <code>max</code> given, calls the block with at most <code>max</code> child elements:</p>

<pre class="ruby"><span class="ruby-identifier">a</span>.<span class="ruby-identifier">each_element_with_attribute</span>(<span class="ruby-string">&#39;id&#39;</span>, <span class="ruby-string">&#39;1&#39;</span>, <span class="ruby-value">1</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">e</span> }
</pre>

<p>Output:</p>

<pre>&lt;b id=&#39;1&#39;/&gt;</pre>

<p>With all arguments given, including <code>xpath</code>, calls the block with only those child elements that meet the first three criteria, and also match the given <code>xpath</code>:</p>

<pre class="ruby"><span class="ruby-identifier">a</span>.<span class="ruby-identifier">each_element_with_attribute</span>(<span class="ruby-string">&#39;id&#39;</span>, <span class="ruby-string">&#39;1&#39;</span>, <span class="ruby-value">2</span>, <span class="ruby-string">&#39;//d&#39;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">e</span> }
</pre>

<p>Output:</p>

<pre>&lt;d id=&#39;1&#39;/&gt;</pre>

                              <div class="method-source-code" id="each_element_with_attribute-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 846</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">each_element_with_attribute</span>( <span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>=<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">max</span>=<span class="ruby-value">0</span>, <span class="ruby-identifier">name</span>=<span class="ruby-keyword">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span> ) <span class="ruby-comment"># :yields: Element</span>
  <span class="ruby-identifier">each_with_something</span>( <span class="ruby-identifier">proc</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">child</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span>
      <span class="ruby-identifier">child</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-identifier">key</span>] <span class="ruby-operator">!=</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">child</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-identifier">key</span>]<span class="ruby-operator">==</span><span class="ruby-identifier">value</span>
    <span class="ruby-keyword">end</span>
  }, <span class="ruby-identifier">max</span>, <span class="ruby-identifier">name</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span> )
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each_element_with_text" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          each_element_with_text(text = nil, max = 0, xpath = nil) {|e| ... }
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Calls the given block with each child element that meets given criteria.</p>

<p>With no arguments, calls the block with each child element that has text:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&#39;&lt;a&gt;&lt;b&gt;b&lt;/b&gt;&lt;c&gt;b&lt;/c&gt;&lt;d&gt;d&lt;/d&gt;&lt;e/&gt;&lt;/a&gt;&#39;</span>
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">each_element_with_text</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">e</span> }
</pre>

<p>Output:</p>

<pre>&lt;b&gt; ... &lt;/&gt;
&lt;c&gt; ... &lt;/&gt;
&lt;d&gt; ... &lt;/&gt;</pre>

<p>With the single string argument <code>text</code>, calls the block with each element that has exactly that text:</p>

<pre class="ruby"><span class="ruby-identifier">a</span>.<span class="ruby-identifier">each_element_with_text</span>(<span class="ruby-string">&#39;b&#39;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">e</span> }
</pre>

<p>Output:</p>

<pre>&lt;b&gt; ... &lt;/&gt;
&lt;c&gt; ... &lt;/&gt;</pre>

<p>With argument <code>text</code> and integer argument <code>max</code>, calls the block with at most <code>max</code> elements:</p>

<pre class="ruby"><span class="ruby-identifier">a</span>.<span class="ruby-identifier">each_element_with_text</span>(<span class="ruby-string">&#39;b&#39;</span>, <span class="ruby-value">1</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">e</span> }
</pre>

<p>Output:</p>

<pre>&lt;b&gt; ... &lt;/&gt;</pre>

<p>With all arguments given, including <code>xpath</code>, calls the block with only those child elements that meet the first two criteria, and also match the given <code>xpath</code>:</p>

<pre class="ruby"><span class="ruby-identifier">a</span>.<span class="ruby-identifier">each_element_with_text</span>(<span class="ruby-string">&#39;b&#39;</span>, <span class="ruby-value">2</span>, <span class="ruby-string">&#39;//c&#39;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">e</span> }
</pre>

<p>Output:</p>

<pre>&lt;c&gt; ... &lt;/&gt;</pre>

                              <div class="method-source-code" id="each_element_with_text-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 903</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">each_element_with_text</span>( <span class="ruby-identifier">text</span>=<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">max</span>=<span class="ruby-value">0</span>, <span class="ruby-identifier">name</span>=<span class="ruby-keyword">nil</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span> ) <span class="ruby-comment"># :yields: Element</span>
  <span class="ruby-identifier">each_with_something</span>( <span class="ruby-identifier">proc</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">child</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">text</span>.<span class="ruby-identifier">nil?</span>
      <span class="ruby-identifier">child</span>.<span class="ruby-identifier">has_text?</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">child</span>.<span class="ruby-identifier">text</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">text</span>
    <span class="ruby-keyword">end</span>
  }, <span class="ruby-identifier">max</span>, <span class="ruby-identifier">name</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span> )
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-get_elements" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          get_elements(xpath)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an array of the elements that match the given <code>xpath</code>:</p>

<pre class="ruby"><span class="ruby-identifier">xml_string</span> = <span class="ruby-identifier">&lt;&lt;-EOT</span>
<span class="ruby-value">&lt;root&gt;
  &lt;a level=&#39;1&#39;&gt;
    &lt;a level=&#39;2&#39;/&gt;
  &lt;/a&gt;
&lt;/root&gt;
</span><span class="ruby-identifier">EOT</span>
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">xml_string</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">get_elements</span>(<span class="ruby-string">&#39;//a&#39;</span>) <span class="ruby-comment"># =&gt; [&lt;a level=&#39;1&#39;&gt; ... &lt;/&gt;, &lt;a level=&#39;2&#39;/&gt;]</span>
</pre>

                              <div class="method-source-code" id="get_elements-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 948</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">get_elements</span>( <span class="ruby-identifier">xpath</span> )
  <span class="ruby-ivar">@elements</span>.<span class="ruby-identifier">to_a</span>( <span class="ruby-identifier">xpath</span> )
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-get_text" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          get_text(xpath = nil) &rarr; text_node or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the first text node child in a specified element, if it exists, <code>nil</code> otherwise.</p>

<p>With no argument, returns the first text node from <code>self</code>:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&quot;&lt;p&gt;some text &lt;b&gt;this is bold!&lt;/b&gt; more text&lt;/p&gt;&quot;</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">get_text</span>.<span class="ruby-identifier">class</span> <span class="ruby-comment"># =&gt; REXML::Text</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">get_text</span>       <span class="ruby-comment"># =&gt; &quot;some text &quot;</span>
</pre>

<p>With argument <code>xpath</code>, returns the first text node from the element that matches <code>xpath</code>:</p>

<pre class="ruby"><span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">get_text</span>(<span class="ruby-value">1</span>) <span class="ruby-comment"># =&gt; &quot;this is bold!&quot;</span>
</pre>

                              <div class="method-source-code" id="get_text-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1052</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">get_text</span> <span class="ruby-identifier">path</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-identifier">rv</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">path</span>
    <span class="ruby-identifier">element</span> = <span class="ruby-ivar">@elements</span>[ <span class="ruby-identifier">path</span> ]
    <span class="ruby-identifier">rv</span> = <span class="ruby-identifier">element</span>.<span class="ruby-identifier">get_text</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">nil?</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">rv</span> = <span class="ruby-ivar">@children</span>.<span class="ruby-identifier">find</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">node</span><span class="ruby-operator">|</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Text</span> }
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">rv</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-has_attributes-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          has_attributes? &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the element has attributes, <code>false</code> otherwise:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&lt;root&gt;&lt;a attr=&quot;val&quot;/&gt;&lt;b/&gt;&lt;/root&gt;&#39;</span>)
<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span> = <span class="ruby-operator">*</span><span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">has_attributes?</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">has_attributes?</span> <span class="ruby-comment"># =&gt; false</span>
</pre>

                              <div class="method-source-code" id="has_attributes-3F-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1319</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">has_attributes?</span>
  <span class="ruby-keyword">return</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@attributes</span>.<span class="ruby-identifier">empty?</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-has_elements-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          has_elements?
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the element has one or more element children, <code>false</code> otherwise:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&#39;&lt;a&gt;&lt;b/&gt;text&lt;c/&gt;&lt;/a&gt;&#39;</span>
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>              <span class="ruby-comment"># =&gt; &lt;a&gt; ... &lt;/&gt;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">has_elements?</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">b</span> = <span class="ruby-identifier">a</span>[<span class="ruby-value">0</span>]        <span class="ruby-comment"># =&gt; &lt;b/&gt;</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">has_elements?</span> <span class="ruby-comment"># =&gt; false</span>
</pre>

                              <div class="method-source-code" id="has_elements-3F-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 793</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">has_elements?</span>
  <span class="ruby-operator">!</span><span class="ruby-ivar">@elements</span>.<span class="ruby-identifier">empty?</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-has_text-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          has_text? &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the element has one or more text noded, <code>false</code> otherwise:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&#39;&lt;a&gt;&lt;b/&gt;text&lt;c/&gt;&lt;/a&gt;&#39;</span>
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">has_text?</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">b</span> = <span class="ruby-identifier">a</span>[<span class="ruby-value">0</span>]
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">has_text?</span> <span class="ruby-comment"># =&gt; false</span>
</pre>

                              <div class="method-source-code" id="has_text-3F-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1001</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">has_text?</span>
  <span class="ruby-keyword">not</span> <span class="ruby-identifier">text</span>().<span class="ruby-identifier">nil?</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-ignore_whitespace_nodes" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          ignore_whitespace_nodes
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if whitespace nodes are ignored for the element.</p>

<p>See <a href="../doc/rexml/context_rdoc.html">Element Context</a>.</p>

                              <div class="method-source-code" id="ignore_whitespace_nodes-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 516</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">ignore_whitespace_nodes</span>
  <span class="ruby-ivar">@ignore_whitespace_nodes</span> = <span class="ruby-keyword">false</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@context</span>
    <span class="ruby-keyword">if</span> <span class="ruby-ivar">@context</span>[<span class="ruby-value">:ignore_whitespace_nodes</span>]
      <span class="ruby-ivar">@ignore_whitespace_nodes</span> =
        (<span class="ruby-ivar">@context</span>[<span class="ruby-value">:ignore_whitespace_nodes</span>] <span class="ruby-operator">==</span> <span class="ruby-value">:all</span> <span class="ruby-keyword">or</span>
         <span class="ruby-ivar">@context</span>[<span class="ruby-value">:ignore_whitespace_nodes</span>].<span class="ruby-identifier">include?</span> <span class="ruby-identifier">expanded_name</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-inspect" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          inspect &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a string representation of the element.</p>

<p>For an element with no attributes and no children, shows the element name:</p>

<pre class="ruby"><span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">inspect</span> <span class="ruby-comment"># =&gt; &quot;&lt;UNDEFINED/&gt;&quot;</span>
</pre>

<p>Shows attributes, if any:</p>

<pre class="ruby"><span class="ruby-identifier">e</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">add_attributes</span>({<span class="ruby-string">&#39;bar&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">0</span>, <span class="ruby-string">&#39;baz&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">1</span>})
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">inspect</span> <span class="ruby-comment"># =&gt; &quot;&lt;foo bar=&#39;0&#39; baz=&#39;1&#39;/&gt;&quot;</span>
</pre>

<p>Shows an ellipsis (<code>...</code>), if there are child elements:</p>

<pre class="ruby"><span class="ruby-identifier">e</span>.<span class="ruby-identifier">add_element</span>(<span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;bar&#39;</span>))
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">add_element</span>(<span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;baz&#39;</span>))
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">inspect</span> <span class="ruby-comment"># =&gt; &quot;&lt;foo bar=&#39;0&#39; baz=&#39;1&#39;&gt; ... &lt;/&gt;&quot;</span>
</pre>

                              <div class="method-source-code" id="inspect-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 366</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">inspect</span>
  <span class="ruby-identifier">rv</span> = <span class="ruby-string">&quot;&lt;#@expanded_name&quot;</span>

  <span class="ruby-ivar">@attributes</span>.<span class="ruby-identifier">each_attribute</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attr</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">rv</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot; &quot;</span>
    <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">write</span>( <span class="ruby-identifier">rv</span>, <span class="ruby-value">0</span> )
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">children</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
    <span class="ruby-identifier">rv</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;&gt; ... &lt;/&gt;&quot;</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">rv</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;/&gt;&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-instructions" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          instructions &rarr; array_of_instruction_children
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a frozen array of the <a href="Instruction.html"><code>REXML::Instruction</code></a> children of the element:</p>

<pre class="ruby"><span class="ruby-identifier">xml_string</span> = <span class="ruby-identifier">&lt;&lt;-EOT</span>
<span class="ruby-value">  &lt;root&gt;
    &lt;?target0 foo?&gt;
    &lt;?target1 bar?&gt;
  &lt;/root&gt;
</span><span class="ruby-identifier">EOT</span>
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">xml_string</span>)
<span class="ruby-identifier">is</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">instructions</span>
<span class="ruby-identifier">is</span>.<span class="ruby-identifier">frozen?</span>             <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">is</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">i</span>.<span class="ruby-identifier">class</span> } <span class="ruby-comment"># =&gt; [REXML::Instruction, REXML::Instruction]</span>
<span class="ruby-identifier">is</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">i</span>.<span class="ruby-identifier">to_s</span> }  <span class="ruby-comment"># =&gt; [&quot;&lt;?target0 foo?&gt;&quot;, &quot;&lt;?target1 bar?&gt;&quot;]</span>
</pre>

                              <div class="method-source-code" id="instructions-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1466</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">instructions</span>
  <span class="ruby-identifier">find_all</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">child</span><span class="ruby-operator">|</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Instruction</span> }.<span class="ruby-identifier">freeze</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-namespace" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          namespace(prefix = nil) &rarr; string_uri or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the string namespace URI for the element, possibly deriving from one of its ancestors.</p>

<pre class="ruby"><span class="ruby-identifier">xml_string</span> = <span class="ruby-identifier">&lt;&lt;-EOT</span>
<span class="ruby-value">  &lt;root&gt;
     &lt;a xmlns=&#39;1&#39; xmlns:y=&#39;2&#39;&gt;
       &lt;b/&gt;
       &lt;c xmlns:z=&#39;3&#39;/&gt;
     &lt;/a&gt;
  &lt;/root&gt;
</span><span class="ruby-identifier">EOT</span>
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">xml_string</span>)
<span class="ruby-identifier">b</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">elements</span>[<span class="ruby-string">&#39;//b&#39;</span>]
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">namespace</span>      <span class="ruby-comment"># =&gt; &quot;1&quot;</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">namespace</span>(<span class="ruby-string">&#39;y&#39;</span>) <span class="ruby-comment"># =&gt; &quot;2&quot;</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">namespace</span>(<span class="ruby-string">&#39;nosuch&#39;</span>) <span class="ruby-comment"># =&gt; nil</span>
</pre>

                              <div class="method-source-code" id="namespace-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 621</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">namespace</span>(<span class="ruby-identifier">prefix</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">prefix</span>.<span class="ruby-identifier">nil?</span>
    <span class="ruby-identifier">prefix</span> = <span class="ruby-identifier">prefix</span>()
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">prefix</span> <span class="ruby-operator">==</span> <span class="ruby-string">&#39;&#39;</span>
    <span class="ruby-identifier">prefix</span> = <span class="ruby-string">&quot;xmlns&quot;</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">prefix</span> = <span class="ruby-node">&quot;xmlns:#{prefix}&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">prefix</span>[<span class="ruby-value">0</span>,<span class="ruby-value">5</span>] <span class="ruby-operator">==</span> <span class="ruby-string">&#39;xmlns&#39;</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">ns</span> = <span class="ruby-identifier">attributes</span>[ <span class="ruby-identifier">prefix</span> ]
  <span class="ruby-identifier">ns</span> = <span class="ruby-identifier">parent</span>.<span class="ruby-identifier">namespace</span>(<span class="ruby-identifier">prefix</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">ns</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">parent</span>
  <span class="ruby-identifier">ns</span> = <span class="ruby-string">&#39;&#39;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">ns</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">prefix</span> <span class="ruby-operator">==</span> <span class="ruby-string">&#39;xmlns&#39;</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">ns</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-namespaces" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          namespaces &rarr; array_of_namespace_names
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a hash of all defined namespaces in the element and its ancestors:</p>

<pre class="ruby"><span class="ruby-identifier">xml_string</span> = <span class="ruby-identifier">&lt;&lt;-EOT</span>
<span class="ruby-value">  &lt;root&gt;
     &lt;a xmlns:x=&#39;1&#39; xmlns:y=&#39;2&#39;&gt;
       &lt;b/&gt;
       &lt;c xmlns:z=&#39;3&#39;/&gt;
     &lt;/a&gt;
  &lt;/root&gt;
</span><span class="ruby-identifier">EOT</span>
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">xml_string</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">elements</span>[<span class="ruby-string">&#39;//a&#39;</span>].<span class="ruby-identifier">namespaces</span> <span class="ruby-comment"># =&gt; {&quot;x&quot;=&gt;&quot;1&quot;, &quot;y&quot;=&gt;&quot;2&quot;}</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">elements</span>[<span class="ruby-string">&#39;//b&#39;</span>].<span class="ruby-identifier">namespaces</span> <span class="ruby-comment"># =&gt; {&quot;x&quot;=&gt;&quot;1&quot;, &quot;y&quot;=&gt;&quot;2&quot;}</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">elements</span>[<span class="ruby-string">&#39;//c&#39;</span>].<span class="ruby-identifier">namespaces</span> <span class="ruby-comment"># =&gt; {&quot;x&quot;=&gt;&quot;1&quot;, &quot;y&quot;=&gt;&quot;2&quot;, &quot;z&quot;=&gt;&quot;3&quot;}</span>
</pre>

                              <div class="method-source-code" id="namespaces-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 594</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">namespaces</span>
  <span class="ruby-identifier">namespaces</span> = {}
  <span class="ruby-identifier">namespaces</span> = <span class="ruby-identifier">parent</span>.<span class="ruby-identifier">namespaces</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">parent</span>
  <span class="ruby-identifier">namespaces</span> = <span class="ruby-identifier">namespaces</span>.<span class="ruby-identifier">merge</span>( <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">namespaces</span> )
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">namespaces</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-next_element" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          next_element
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the next sibling that is an element if it exists, <code>niL</code> otherwise:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&#39;&lt;a&gt;&lt;b/&gt;text&lt;c/&gt;&lt;/a&gt;&#39;</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">elements</span>[<span class="ruby-string">&#39;b&#39;</span>].<span class="ruby-identifier">next_element</span> <span class="ruby-comment">#-&gt; &lt;c/&gt;</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">elements</span>[<span class="ruby-string">&#39;c&#39;</span>].<span class="ruby-identifier">next_element</span> <span class="ruby-comment">#-&gt; nil</span>
</pre>

                              <div class="method-source-code" id="next_element-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 962</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">next_element</span>
  <span class="ruby-identifier">element</span> = <span class="ruby-identifier">next_sibling</span>
  <span class="ruby-identifier">element</span> = <span class="ruby-identifier">element</span>.<span class="ruby-identifier">next_sibling</span> <span class="ruby-keyword">until</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Element</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">element</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-node_type" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          node_type &rarr; :element
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns symbol <code>:element</code>:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&lt;a/&gt;&#39;</span>)
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>  <span class="ruby-comment"># =&gt; &lt;a/&gt;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">node_type</span> <span class="ruby-comment"># =&gt; :element</span>
</pre>

                              <div class="method-source-code" id="node_type-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1167</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">node_type</span>
  <span class="ruby-value">:element</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-prefixes" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          prefixes &rarr; array_of_namespace_prefixes
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an array of the string prefixes (names) of all defined namespaces in the element and its ancestors:</p>

<pre class="ruby"><span class="ruby-identifier">xml_string</span> = <span class="ruby-identifier">&lt;&lt;-EOT</span>
<span class="ruby-value">  &lt;root&gt;
     &lt;a xmlns:x=&#39;1&#39; xmlns:y=&#39;2&#39;&gt;
       &lt;b/&gt;
       &lt;c xmlns:z=&#39;3&#39;/&gt;
     &lt;/a&gt;
  &lt;/root&gt;
</span><span class="ruby-identifier">EOT</span>
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">xml_string</span>, {<span class="ruby-value">compress_whitespace:</span> <span class="ruby-value">:all</span>})
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">elements</span>[<span class="ruby-string">&#39;//a&#39;</span>].<span class="ruby-identifier">prefixes</span> <span class="ruby-comment"># =&gt; [&quot;x&quot;, &quot;y&quot;]</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">elements</span>[<span class="ruby-string">&#39;//b&#39;</span>].<span class="ruby-identifier">prefixes</span> <span class="ruby-comment"># =&gt; [&quot;x&quot;, &quot;y&quot;]</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">elements</span>[<span class="ruby-string">&#39;//c&#39;</span>].<span class="ruby-identifier">prefixes</span> <span class="ruby-comment"># =&gt; [&quot;x&quot;, &quot;y&quot;, &quot;z&quot;]</span>
</pre>

                              <div class="method-source-code" id="prefixes-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 568</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">prefixes</span>
  <span class="ruby-identifier">prefixes</span> = []
  <span class="ruby-identifier">prefixes</span> = <span class="ruby-identifier">parent</span>.<span class="ruby-identifier">prefixes</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">parent</span>
  <span class="ruby-identifier">prefixes</span> <span class="ruby-operator">|=</span> <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">prefixes</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">prefixes</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-previous_element" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          previous_element
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the previous sibling that is an element if it exists, <code>niL</code> otherwise:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&#39;&lt;a&gt;&lt;b/&gt;text&lt;c/&gt;&lt;/a&gt;&#39;</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">elements</span>[<span class="ruby-string">&#39;c&#39;</span>].<span class="ruby-identifier">previous_element</span> <span class="ruby-comment">#-&gt; &lt;b/&gt;</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">elements</span>[<span class="ruby-string">&#39;b&#39;</span>].<span class="ruby-identifier">previous_element</span> <span class="ruby-comment">#-&gt; nil</span>
</pre>

                              <div class="method-source-code" id="previous_element-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 978</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">previous_element</span>
  <span class="ruby-identifier">element</span> = <span class="ruby-identifier">previous_sibling</span>
  <span class="ruby-identifier">element</span> = <span class="ruby-identifier">element</span>.<span class="ruby-identifier">previous_sibling</span> <span class="ruby-keyword">until</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">element</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Element</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">element</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-raw" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          raw
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if raw mode is set for the element.</p>

<p>See <a href="../doc/rexml/context_rdoc.html">Element Context</a>.</p>

<p>The evaluation is tested against <code>expanded_name</code>, and so is namespace sensitive.</p>

                              <div class="method-source-code" id="raw-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 536</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">raw</span>
  <span class="ruby-ivar">@raw</span> = (<span class="ruby-ivar">@context</span> <span class="ruby-keyword">and</span> <span class="ruby-ivar">@context</span>[<span class="ruby-value">:raw</span>] <span class="ruby-keyword">and</span>
          (<span class="ruby-ivar">@context</span>[<span class="ruby-value">:raw</span>] <span class="ruby-operator">==</span> <span class="ruby-value">:all</span> <span class="ruby-keyword">or</span>
           <span class="ruby-ivar">@context</span>[<span class="ruby-value">:raw</span>].<span class="ruby-identifier">include?</span> <span class="ruby-identifier">expanded_name</span>))
  <span class="ruby-ivar">@raw</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-root" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          root &rarr; element
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the most distant <em>element</em> (not document) ancestor of the element:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&lt;a&gt;&lt;b&gt;&lt;c/&gt;&lt;/b&gt;&lt;/a&gt;&#39;</span>)
<span class="ruby-identifier">top_element</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">first</span>
<span class="ruby-identifier">child</span> = <span class="ruby-identifier">top_element</span>.<span class="ruby-identifier">first</span>
<span class="ruby-identifier">top_element</span>.<span class="ruby-identifier">root</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">top_element</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">child</span>.<span class="ruby-identifier">root</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">top_element</span>       <span class="ruby-comment"># =&gt; true</span>
</pre>

<p>For a document, returns the topmost element:</p>

<pre class="ruby"><span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">top_element</span> <span class="ruby-comment"># =&gt; true</span>
</pre>

<p>Related: <a href="Element.html#method-i-root_node"><code>root_node</code></a>, <a href="Element.html#method-i-document"><code>document</code></a>.</p>

                              <div class="method-source-code" id="root-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 451</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">root</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">elements</span>[<span class="ruby-value">1</span>] <span class="ruby-keyword">if</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Document</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">parent</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Document</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">parent</span>.<span class="ruby-identifier">nil?</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">parent</span>.<span class="ruby-identifier">root</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-root_node" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          root_node &rarr; document or element
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the most distant ancestor of <code>self</code>.</p>

<p>When the element is part of a document, returns the root node of the document. Note that the root node is different from the document element; in this example <code>a</code> is document element and the root node is its parent:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&lt;a&gt;&lt;b&gt;&lt;c/&gt;&lt;/b&gt;&lt;/a&gt;&#39;</span>)
<span class="ruby-identifier">top_element</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">first</span>      <span class="ruby-comment"># =&gt; &lt;a&gt; ... &lt;/&gt;</span>
<span class="ruby-identifier">child</span> = <span class="ruby-identifier">top_element</span>.<span class="ruby-identifier">first</span>  <span class="ruby-comment"># =&gt; &lt;b&gt; ... &lt;/&gt;</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">root_node</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">d</span>           <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">top_element</span>.<span class="ruby-identifier">root_node</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">d</span> <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">child</span>.<span class="ruby-identifier">root_node</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">d</span>       <span class="ruby-comment"># =&gt; true</span>
</pre>

<p>When the element is not part of a document, but does have ancestor elements, returns the most distant ancestor element:</p>

<pre class="ruby"><span class="ruby-identifier">e0</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">e1</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;bar&#39;</span>)
<span class="ruby-identifier">e1</span>.<span class="ruby-identifier">parent</span> = <span class="ruby-identifier">e0</span>
<span class="ruby-identifier">e2</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;baz&#39;</span>)
<span class="ruby-identifier">e2</span>.<span class="ruby-identifier">parent</span> = <span class="ruby-identifier">e1</span>
<span class="ruby-identifier">e2</span>.<span class="ruby-identifier">root_node</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">e0</span> <span class="ruby-comment"># =&gt; true</span>
</pre>

<p>When the element has no ancestor elements, returns <code>self</code>:</p>

<pre class="ruby"><span class="ruby-identifier">e</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">root_node</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">e</span> <span class="ruby-comment"># =&gt; true</span>
</pre>

<p>Related: <a href="Element.html#method-i-root"><code>root</code></a>, <a href="Element.html#method-i-document"><code>document</code></a>.</p>

                              <div class="method-source-code" id="root_node-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 430</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">root_node</span>
  <span class="ruby-identifier">parent</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">?</span> <span class="ruby-keyword">self</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">parent</span>.<span class="ruby-identifier">root_node</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-text" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          text(xpath = nil) &rarr; text_string or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the text string from the first text node child in a specified element, if it exists, <code>nil</code> otherwise.</p>

<p>With no argument, returns the text from the first text node in <code>self</code>:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&quot;&lt;p&gt;some text &lt;b&gt;this is bold!&lt;/b&gt; more text&lt;/p&gt;&quot;</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">text</span>.<span class="ruby-identifier">class</span> <span class="ruby-comment"># =&gt; String</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">text</span>       <span class="ruby-comment"># =&gt; &quot;some text &quot;</span>
</pre>

<p>With argument <code>xpath</code>, returns text from the first text node in the element that matches <code>xpath</code>:</p>

<pre class="ruby"><span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">text</span>(<span class="ruby-value">1</span>) <span class="ruby-comment"># =&gt; &quot;this is bold!&quot;</span>
</pre>

<p>Note that an element may have multiple text nodes, possibly separated by other non-text children, as above. Even so, the returned value is the string text from the first such node.</p>

<p>Note also that the text note is retrieved by method <a href="Element.html#method-i-get_text"><code>get_text</code></a>, and so is always normalized text.</p>

                              <div class="method-source-code" id="text-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1029</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">text</span>( <span class="ruby-identifier">path</span> = <span class="ruby-keyword">nil</span> )
  <span class="ruby-identifier">rv</span> = <span class="ruby-identifier">get_text</span>(<span class="ruby-identifier">path</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">rv</span>.<span class="ruby-identifier">value</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">rv</span>.<span class="ruby-identifier">nil?</span>
  <span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-text-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          text = string &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          text = nil &rarr; nil
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Adds, replaces, or removes the first text node child in the element.</p>

<p>With string argument <code>string</code>, creates a new REXML::Text node containing that string, honoring the current settings for whitespace and row, then places the node as the first text child in the element; returns <code>string</code>.</p>

<p>If the element has no text child, the text node is added:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&#39;&lt;a&gt;&lt;b/&gt;&lt;/a&gt;&#39;</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">text</span> = <span class="ruby-string">&#39;foo&#39;</span> <span class="ruby-comment">#-&gt; &#39;&lt;a&gt;&lt;b/&gt;foo&lt;/a&gt;&#39;</span>
</pre>

<p>If the element has a text child, it is replaced:</p>

<pre class="ruby"><span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">text</span> = <span class="ruby-string">&#39;bar&#39;</span> <span class="ruby-comment">#-&gt; &#39;&lt;a&gt;&lt;b/&gt;bar&lt;/a&gt;&#39;</span>
</pre>

<p>With argument <code>nil</code>, removes the first text child:</p>

<pre class="ruby"><span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">text</span> = <span class="ruby-keyword">nil</span>   <span class="ruby-comment">#-&gt; &#39;&lt;a&gt;&lt;b/&gt;&lt;c/&gt;&lt;/a&gt;&#39;</span>
</pre>

                              <div class="method-source-code" id="text-3D-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1088</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">text=</span>( <span class="ruby-identifier">text</span> )
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">text</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">String</span>
    <span class="ruby-identifier">text</span> = <span class="ruby-constant">Text</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">text</span>, <span class="ruby-identifier">whitespace</span>(), <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">raw</span>() )
  <span class="ruby-keyword">elsif</span> <span class="ruby-operator">!</span><span class="ruby-identifier">text</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword">and</span> <span class="ruby-operator">!</span><span class="ruby-identifier">text</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Text</span>
    <span class="ruby-identifier">text</span> = <span class="ruby-constant">Text</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">text</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">whitespace</span>(), <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">raw</span>() )
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">old_text</span> = <span class="ruby-identifier">get_text</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">text</span>.<span class="ruby-identifier">nil?</span>
    <span class="ruby-identifier">old_text</span>.<span class="ruby-identifier">remove</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">old_text</span>.<span class="ruby-identifier">nil?</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">old_text</span>.<span class="ruby-identifier">nil?</span>
      <span class="ruby-keyword">self</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">text</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">old_text</span>.<span class="ruby-identifier">replace_with</span>( <span class="ruby-identifier">text</span> )
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-texts" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          texts &rarr; array_of_text_children
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a frozen array of the <a href="Text.html"><code>REXML::Text</code></a> children of the element:</p>

<pre class="ruby"><span class="ruby-identifier">xml_string</span> = <span class="ruby-string">&#39;&lt;root&gt;&lt;a/&gt;text&lt;b/&gt;more&lt;c/&gt;&lt;/root&gt;&#39;</span>
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">xml_string</span>)
<span class="ruby-identifier">ts</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">texts</span>
<span class="ruby-identifier">ts</span>.<span class="ruby-identifier">frozen?</span>            <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">ts</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span> <span class="ruby-identifier">t</span>.<span class="ruby-identifier">class</span> } <span class="ruby-comment"># =&gt; [REXML::Text, REXML::Text]</span>
<span class="ruby-identifier">ts</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span> <span class="ruby-identifier">t</span>.<span class="ruby-identifier">to_s</span> }  <span class="ruby-comment"># =&gt; [&quot;text&quot;, &quot;more&quot;]</span>
</pre>

                              <div class="method-source-code" id="texts-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1482</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">texts</span>
  <span class="ruby-identifier">find_all</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">child</span><span class="ruby-operator">|</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Text</span> }.<span class="ruby-identifier">freeze</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-whitespace" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          whitespace
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if whitespace is respected for this element, <code>false</code> otherwise.</p>

<p>See <a href="../doc/rexml/context_rdoc.html">Element Context</a>.</p>

<p>The evaluation is tested against the element’s <code>expanded_name</code>, and so is namespace-sensitive.</p>

                              <div class="method-source-code" id="whitespace-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 493</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">whitespace</span>
  <span class="ruby-ivar">@whitespace</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@context</span>
    <span class="ruby-keyword">if</span> <span class="ruby-ivar">@context</span>[<span class="ruby-value">:respect_whitespace</span>]
      <span class="ruby-ivar">@whitespace</span> = (<span class="ruby-ivar">@context</span>[<span class="ruby-value">:respect_whitespace</span>] <span class="ruby-operator">==</span> <span class="ruby-value">:all</span> <span class="ruby-keyword">or</span>
                     <span class="ruby-ivar">@context</span>[<span class="ruby-value">:respect_whitespace</span>].<span class="ruby-identifier">include?</span> <span class="ruby-identifier">expanded_name</span>)
    <span class="ruby-keyword">end</span>
    <span class="ruby-ivar">@whitespace</span> = <span class="ruby-keyword">false</span> <span class="ruby-keyword">if</span> (<span class="ruby-ivar">@context</span>[<span class="ruby-value">:compress_whitespace</span>] <span class="ruby-keyword">and</span>
                            (<span class="ruby-ivar">@context</span>[<span class="ruby-value">:compress_whitespace</span>] <span class="ruby-operator">==</span> <span class="ruby-value">:all</span> <span class="ruby-keyword">or</span>
                             <span class="ruby-ivar">@context</span>[<span class="ruby-value">:compress_whitespace</span>].<span class="ruby-identifier">include?</span> <span class="ruby-identifier">expanded_name</span>)
                           )
  <span class="ruby-keyword">end</span>
  <span class="ruby-ivar">@whitespace</span> = <span class="ruby-keyword">true</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@whitespace</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">false</span>
  <span class="ruby-ivar">@whitespace</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-write" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">write</span><span
                                class="method-args">(output=$stdout, indent=-1, transitive=false, ie_hack=false)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <h2 id="method-i-write-label-DEPRECATED">DEPRECATED<span><a href="#method-i-write-label-DEPRECATED">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>See <a href="Formatters.html"><code>REXML::Formatters</code></a></p>

<p>Writes out this element, and recursively, all children.</p>
<dl class="rdoc-list note-list"><dt>output
<dd>
<p>output an object which supports ‘&lt;&lt; string’; this is where the</p>
</dd></dl>

<pre>document will be written.</pre>
<dl class="rdoc-list note-list"><dt>indent
<dd>
<p>An integer.  If -1, no indenting will be used; otherwise, the indentation will be this number of spaces, and children will be indented an additional amount.  Defaults to -1</p>
</dd><dt>transitive
<dd>
<p>If transitive is true and indent is &gt;= 0, then the output will be pretty-printed in such a way that the added whitespace does not affect the parse tree of the document</p>
</dd><dt>ie_hack
<dd>
<p>This hack inserts a space before the /&gt; on empty tags to address a limitation of Internet Explorer.  Defaults to false</p>
</dd></dl>

<pre class="ruby"><span class="ruby-identifier">out</span> = <span class="ruby-string">&#39;&#39;</span>
<span class="ruby-identifier">doc</span>.<span class="ruby-identifier">write</span>( <span class="ruby-identifier">out</span> )     <span class="ruby-comment">#-&gt; doc is written to the string &#39;out&#39;</span>
<span class="ruby-identifier">doc</span>.<span class="ruby-identifier">write</span>( <span class="ruby-identifier">$stdout</span> ) <span class="ruby-comment">#-&gt; doc written to the console</span>
</pre>

                              <div class="method-source-code" id="write-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1508</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">write</span>(<span class="ruby-identifier">output</span>=<span class="ruby-identifier">$stdout</span>, <span class="ruby-identifier">indent</span>=<span class="ruby-value">-1</span>, <span class="ruby-identifier">transitive</span>=<span class="ruby-keyword">false</span>, <span class="ruby-identifier">ie_hack</span>=<span class="ruby-keyword">false</span>)
  <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-node">&quot;#{self.class.name}.write is deprecated.  See REXML::Formatters&quot;</span>, <span class="ruby-value">uplevel:</span> <span class="ruby-value">1</span>)
  <span class="ruby-identifier">formatter</span> = <span class="ruby-keyword">if</span> <span class="ruby-identifier">indent</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">-1</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">transitive</span>
        <span class="ruby-identifier">require_relative</span> <span class="ruby-string">&quot;formatters/transitive&quot;</span>
        <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Formatters</span><span class="ruby-operator">::</span><span class="ruby-constant">Transitive</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">indent</span>, <span class="ruby-identifier">ie_hack</span> )
      <span class="ruby-keyword">else</span>
        <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Formatters</span><span class="ruby-operator">::</span><span class="ruby-constant">Pretty</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">indent</span>, <span class="ruby-identifier">ie_hack</span> )
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Formatters</span><span class="ruby-operator">::</span><span class="ruby-constant">Default</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">ie_hack</span> )
    <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">formatter</span>.<span class="ruby-identifier">write</span>( <span class="ruby-keyword">self</span>, <span class="ruby-identifier">output</span> )
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-xpath" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          xpath &rarr; string_xpath
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the string xpath to the element relative to the most distant parent:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&lt;a&gt;&lt;b&gt;&lt;c/&gt;&lt;/b&gt;&lt;/a&gt;&#39;</span>)
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span> <span class="ruby-comment"># =&gt; &lt;a&gt; ... &lt;/&gt;</span>
<span class="ruby-identifier">b</span> = <span class="ruby-identifier">a</span>[<span class="ruby-value">0</span>]   <span class="ruby-comment"># =&gt; &lt;b&gt; ... &lt;/&gt;</span>
<span class="ruby-identifier">c</span> = <span class="ruby-identifier">b</span>[<span class="ruby-value">0</span>]   <span class="ruby-comment"># =&gt; &lt;c/&gt;</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">xpath</span>    <span class="ruby-comment"># =&gt; &quot;&quot;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">xpath</span>    <span class="ruby-comment"># =&gt; &quot;/a&quot;</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">xpath</span>    <span class="ruby-comment"># =&gt; &quot;/a/b&quot;</span>
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">xpath</span>    <span class="ruby-comment"># =&gt; &quot;/a/b/c&quot;</span>
</pre>

<p>If there is no parent, returns the expanded name of the element:</p>

<pre class="ruby"><span class="ruby-identifier">e</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">e</span>.<span class="ruby-identifier">xpath</span>    <span class="ruby-comment"># =&gt; &quot;foo&quot;</span>
</pre>

                              <div class="method-source-code" id="xpath-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1191</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">xpath</span>
  <span class="ruby-identifier">path_elements</span> = []
  <span class="ruby-identifier">cur</span> = <span class="ruby-keyword">self</span>
  <span class="ruby-identifier">path_elements</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">__to_xpath_helper</span>( <span class="ruby-keyword">self</span> )
  <span class="ruby-keyword">while</span> <span class="ruby-identifier">cur</span>.<span class="ruby-identifier">parent</span>
    <span class="ruby-identifier">cur</span> = <span class="ruby-identifier">cur</span>.<span class="ruby-identifier">parent</span>
    <span class="ruby-identifier">path_elements</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">__to_xpath_helper</span>( <span class="ruby-identifier">cur</span> )
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">path_elements</span>.<span class="ruby-identifier">reverse</span>.<span class="ruby-identifier">join</span>( <span class="ruby-string">&quot;/&quot;</span> )
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="private-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Private Instance Methods</h3>
                </header>

                  <div id="method-i-__to_xpath_helper" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">__to_xpath_helper</span><span
                                class="method-args">(node)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="__to_xpath_helper-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1525</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">__to_xpath_helper</span> <span class="ruby-identifier">node</span>
  <span class="ruby-identifier">rv</span> = <span class="ruby-identifier">node</span>.<span class="ruby-identifier">expanded_name</span>.<span class="ruby-identifier">clone</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">parent</span>
    <span class="ruby-identifier">results</span> = <span class="ruby-identifier">node</span>.<span class="ruby-identifier">parent</span>.<span class="ruby-identifier">find_all</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">n</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>) <span class="ruby-keyword">and</span> <span class="ruby-identifier">n</span>.<span class="ruby-identifier">expanded_name</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">expanded_name</span>
    }
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">results</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>
      <span class="ruby-identifier">idx</span> = <span class="ruby-identifier">results</span>.<span class="ruby-identifier">index</span>( <span class="ruby-identifier">node</span> )
      <span class="ruby-identifier">rv</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;[#{idx+1}]&quot;</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">rv</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each_with_something" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">each_with_something</span><span
                                class="method-args">( test, max=0, name=nil ) { |child| ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>A private helper method</p>

                              <div class="method-source-code" id="each_with_something-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/element.rb, line 1540</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">each_with_something</span>( <span class="ruby-identifier">test</span>, <span class="ruby-identifier">max</span>=<span class="ruby-value">0</span>, <span class="ruby-identifier">name</span>=<span class="ruby-keyword">nil</span> )
  <span class="ruby-identifier">num</span> = <span class="ruby-value">0</span>
  <span class="ruby-ivar">@elements</span>.<span class="ruby-identifier">each</span>( <span class="ruby-identifier">name</span> ){ <span class="ruby-operator">|</span><span class="ruby-identifier">child</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">yield</span> <span class="ruby-identifier">child</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">test</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">child</span>) <span class="ruby-keyword">and</span> <span class="ruby-identifier">num</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">max</span><span class="ruby-operator">&gt;</span><span class="ruby-value">0</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">num</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">max</span>
  }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>.</p><p><a href="https://jamesbritt.bandcamp.com/">Maximum R+D</a>.  </p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

